Browse Source

Prettify and rename some functions.

main
Rosie Le Faive 4 weeks ago
parent
commit
cafb708fb1
  1. 32
      src/Controller/MetadataProfileController.php

32
src/Controller/MetadataProfileController.php

@ -95,7 +95,7 @@ class MetadataProfileController extends ControllerBase {
$render_array = [
'#type' => 'container',
'#attributes' => ['class' => ['field-info']],
'#weight' => $this->format_weight($field_definition),
'#weight' => $this->formatWeight($field_definition),
'title' => [
'#plain_text' => $field_definition->getLabel(),
'#prefix' => '<h2 id="' . $field_name . '">',
@ -125,11 +125,12 @@ class MetadataProfileController extends ControllerBase {
'description' => [
'#type' => 'markup',
'#markup' => $field_definition->getDescription() ?: $this->t('[No description]'),
'#prefix' => '<b>Description:</b> ',
],
'target_bundles' => [
'#title' => $this->t('Target Bundles'),
'#type' => 'container',
'bundles' => $this->format_target_bundles($field_definition),
'bundles' => $this->formatTargetBundles($field_definition),
],
'search_api' => $this->formatSearchApi($field_definition),
];
@ -141,19 +142,19 @@ class MetadataProfileController extends ControllerBase {
protected function getFieldTableRows(FieldDefinitionInterface $field_definition) {
$rows = [
[$this->t('Type:'), $this->format_type($field_definition)],
[$this->t('Required:'), $this->format_required($field_definition)],
[$this->t('Repeatable:'), $this->format_cardinality($field_definition)],
[$this->t('Type:'), $this->formatType($field_definition)],
[$this->t('Required:'), $this->formatRequired($field_definition)],
[$this->t('Repeatable:'), $this->formatCardinality($field_definition)],
];
// TODO: use a class inheritance method to get entity reference and typed relation in one shot.
if (in_array($field_definition->getType(), ['entity_reference', 'typed_relation'])) {
$rows[] = [$this->t('Create new'), $this->format_create_new($field_definition)];
$rows[] = [$this->t('Create new:'), $this->formatCreateNew($field_definition)];
}
return $rows;
}
protected function format_type(FieldDefinitionInterface $field_definition) {
protected function formatType(FieldDefinitionInterface $field_definition) {
$type = $field_definition->getType();
$type_label = $this->fieldTypePluginManager->getDefinition($type)['label'];
if (in_array($type, ['entity_reference', 'typed_relation'])) {
@ -161,7 +162,7 @@ class MetadataProfileController extends ControllerBase {
}
return $type_label;
}
protected function format_required(FieldDefinitionInterface $field_definition) {
protected function formatRequired(FieldDefinitionInterface $field_definition) {
if ($field_definition->isRequired()) {
return $this->t('Required');
}
@ -173,11 +174,11 @@ 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) {
protected function formatWeight(FieldDefinitionInterface $field_definition) {
return $field_definition->getDisplayOptions('form')['weight'];
}
protected function format_cardinality(FieldDefinitionInterface $field_definition) {
protected function formatCardinality(FieldDefinitionInterface $field_definition) {
$cardinality = $field_definition->getFieldStorageDefinition()->getCardinality();
if ($cardinality == 1) {
return $this->t('Not repeatable');
@ -189,7 +190,7 @@ class MetadataProfileController extends ControllerBase {
return NULL;
}
protected function format_create_new(FieldDefinitionInterface $field_definition) {
protected function formatCreateNew(FieldDefinitionInterface $field_definition) {
$create_new_bundle = $field_definition->getSetting('handler_settings')['auto_create_bundle'];
$create_new = $field_definition->getSetting('handler_settings')['auto_create_bundle'];
if ($create_new) {
@ -200,7 +201,7 @@ class MetadataProfileController extends ControllerBase {
}
}
protected function format_target_bundles(FieldDefinitionInterface $field_definition) {
protected function formatTargetBundles(FieldDefinitionInterface $field_definition) {
$handler = $field_definition->getSetting('handler');
$setting = $field_definition->getSetting('handler_settings');
if (!$setting) {
@ -211,6 +212,9 @@ class MetadataProfileController extends ControllerBase {
if ($handler == 'default:taxonomy_term') {
$bundle_config = $this->entityTypeManager()->getStorage('taxonomy_vocabulary')->load($bundle);
}
if ($handler == 'default:node') {
$bundle_config = $this->entityTypeManager()->getStorage('node_type')->load($bundle);
}
// TODO: ADD NODE ETC
if ($bundle_config) {
$target_bundles[$index] = $bundle_config->get('name') . ' (' . $bundle . ')';
@ -267,8 +271,8 @@ class MetadataProfileController extends ControllerBase {
$build['#rows'][$field_setting_name] = $this->format_solr_field($field_setting_name, $field_setting, $index_config);
}
}
// Get EDTFyear.
// TODO: Get EDTFyear.
}
if (count($build['#rows']) == 0) {
return [];

Loading…
Cancel
Save