|
|
|
|
@ -2,15 +2,17 @@
|
|
|
|
|
|
|
|
|
|
namespace Drupal\metadata_profile\Controller; |
|
|
|
|
|
|
|
|
|
use Drupal\Core\Config\ConfigFactoryInterface; |
|
|
|
|
use Drupal\Core\Controller\ControllerBase; |
|
|
|
|
use Drupal\Core\Field\BaseFieldDefinition; |
|
|
|
|
use Drupal\Core\Field\FieldDefinitionInterface; |
|
|
|
|
use Drupal\Core\Field\FieldStorageDefinitionInterface; |
|
|
|
|
use Drupal\Core\Field\FieldTypePluginManagerInterface; |
|
|
|
|
use Drupal\Core\Messenger\MessengerTrait; |
|
|
|
|
use Drupal\Core\Config\Config; |
|
|
|
|
use Drupal\Core\Url; |
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
use Drupal\Core\Entity\EntityFieldManagerInterface; |
|
|
|
|
use Drupal\Core\Field\Annotation\FieldType; |
|
|
|
|
|
|
|
|
|
class MetadataProfileController extends ControllerBase { |
|
|
|
|
use MessengerTrait; |
|
|
|
|
@ -19,19 +21,25 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
|
|
|
|
|
protected FieldTypePluginManagerInterface $fieldTypePluginManager; |
|
|
|
|
|
|
|
|
|
public function __construct(EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_plugin_manager) { |
|
|
|
|
protected $configFactory; |
|
|
|
|
|
|
|
|
|
public function __construct(EntityFieldManagerInterface $entity_field_manager, |
|
|
|
|
FieldTypePluginManagerInterface $field_type_plugin_manager, |
|
|
|
|
ConfigFactoryInterface $config_factory) { |
|
|
|
|
$this->entityFieldManager = $entity_field_manager; |
|
|
|
|
$this->fieldTypePluginManager = $field_type_plugin_manager; |
|
|
|
|
$this->configFactory = $config_factory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function create(ContainerInterface $container) { |
|
|
|
|
return new static( |
|
|
|
|
$container->get('entity_field.manager'), |
|
|
|
|
$container->get('plugin.manager.field.field_type') |
|
|
|
|
$container->get('plugin.manager.field.field_type'), |
|
|
|
|
$container->get('config.factory') |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function profile( $content_type) { |
|
|
|
|
|
|
|
|
|
// Get core content type information. |
|
|
|
|
@ -110,7 +118,7 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
], |
|
|
|
|
'table' => [ |
|
|
|
|
'#type' => 'table', |
|
|
|
|
'#header' => ['',''], |
|
|
|
|
'#header' => ['Field Configuration',''], |
|
|
|
|
'#rows' => $this->getFieldTableRows($field_definition), |
|
|
|
|
'#attributes' => ['class' => ['field-info-table']], |
|
|
|
|
], |
|
|
|
|
@ -123,7 +131,9 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
'#type' => 'container', |
|
|
|
|
'bundles' => $this->format_target_bundles($field_definition), |
|
|
|
|
], |
|
|
|
|
'search_api' => $this->formatSearchApi($field_definition), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $render_array; |
|
|
|
|
@ -160,6 +170,9 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This does not work - most fields dont have a form weight specified in getDisplayOptions. |
|
|
|
|
*/ |
|
|
|
|
protected function format_weight(FieldDefinitionInterface $field_definition) { |
|
|
|
|
return $field_definition->getDisplayOptions('form')['weight']; |
|
|
|
|
} |
|
|
|
|
@ -211,4 +224,77 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected function formatSearchApi($field_definition) { |
|
|
|
|
if ($this->moduleHandler()->moduleExists('search_api')) { |
|
|
|
|
$build = [ |
|
|
|
|
'#type' => 'table', |
|
|
|
|
'#header' => [ |
|
|
|
|
'col1' => $this->t('Search API field name'), |
|
|
|
|
'col2' => $this->t('Search API machine name'), |
|
|
|
|
'col3' => $this->t('Search API property path'), |
|
|
|
|
'col4' => $this->t('Search API field type'), |
|
|
|
|
'col0' => $this->t('Search API index'), |
|
|
|
|
], |
|
|
|
|
'#rows' => [], |
|
|
|
|
'#caption' => $this->t('Search API') |
|
|
|
|
]; |
|
|
|
|
$storage = $field_definition->getFieldStorageDefinition(); |
|
|
|
|
if ($storage instanceof BaseFieldDefinition) { |
|
|
|
|
// Use property_path to find related fields. |
|
|
|
|
$field_id = 'node.' . $storage->getName(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$field_id = 'field.storage.' . $storage->get('id'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$indexes = $this->configFactory->listAll('search_api.index'); |
|
|
|
|
foreach ($indexes as $index) { |
|
|
|
|
$index_config = $this->config($index); |
|
|
|
|
// Loop over fields. |
|
|
|
|
foreach ($index_config->get('field_settings') as $field_setting_name => $field_setting) { |
|
|
|
|
// Check dependencies. |
|
|
|
|
$field_dependencies = $field_setting['dependencies']['config'] ?: []; |
|
|
|
|
if (in_array($field_id, $field_dependencies)) { |
|
|
|
|
$build['#rows'][$field_setting_name] = $this->format_solr_field($field_setting_name, $field_setting, $index_config); |
|
|
|
|
} |
|
|
|
|
// Check by property path. |
|
|
|
|
if ($field_setting['datasource_id'] == 'entity:node' and $field_setting['property_path'] == $field_definition->getName()) { |
|
|
|
|
$build['#rows'][$field_setting_name] = $this->format_solr_field($field_setting_name, $field_setting, $index_config); |
|
|
|
|
} |
|
|
|
|
// Get Aggregated Fields. |
|
|
|
|
if ($field_setting['property_path'] == 'aggregated_field') { |
|
|
|
|
if (in_array('entity:node/' . $field_definition->getName(), $field_setting['configuration']['fields'])) { |
|
|
|
|
$build['#rows'][$field_setting_name] = $this->format_solr_field($field_setting_name, $field_setting, $index_config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Get EDTFyear. |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (count($build['#rows']) == 0) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $build; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected function format_solr_field($field_setting_name, $field_setting, $index_config) { |
|
|
|
|
$build = [ |
|
|
|
|
'data' => [ |
|
|
|
|
$field_setting['label'], |
|
|
|
|
$field_setting_name, |
|
|
|
|
$field_setting['property_path'], |
|
|
|
|
$field_setting['type'], |
|
|
|
|
$index_config->get('name'), |
|
|
|
|
] |
|
|
|
|
]; |
|
|
|
|
if ($field_setting['property_path'] == 'aggregated_field') { |
|
|
|
|
$build['data'][2] .= ' -' . implode(', -', $field_setting['configuration']['fields']); |
|
|
|
|
} |
|
|
|
|
return $build; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|