Skip to content

Commit

Permalink
Use a later hook to tweak the options.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosiel committed Jun 20, 2024
1 parent d868d32 commit 092c704
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion controlled_access_terms.field_type_categories.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
typed_relation:
label: 'Typed Relation'
description: 'A Reference field, with an associated type selected from a configurable list.'
weight: 10
weight: 100
libraries:
- controlled_access_terms/controlled_access_terms.icons
2 changes: 1 addition & 1 deletion controlled_access_terms.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
controlled_access_terms.icons:
css:
theme:
css/controlled_access_terms.icons-min.css: {}
css/controlled_access_terms.icons.css: {}
22 changes: 22 additions & 0 deletions controlled_access_terms.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\jsonld\Normalizer\NormalizerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldTypeCategoryManagerInterface;
use Drupal\controlled_access_terms\EDTFConverter;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
Expand Down Expand Up @@ -111,6 +112,27 @@ function controlled_access_terms_form_field_ui_field_storage_add_form_alter(&$fo
$form['#attached']['library'][] = 'controlled_access_terms/controlled_access_terms.icons';
}

/**
* Implements hook_field_info_entity_type_ui_definitions_alter().
*/
function controlled_access_terms_field_info_entity_type_ui_definitions_alter(array &$ui_definitions, string $entity_type_id) {
// Put the generic typed relation field last and name it 'Other'.
if (isset($ui_definitions['typed_relation'])) {
$ui_definitions['typed_relation']['label'] = t('Other');
$ui_definitions['typed_relation']['weight'] = 10;
}
// Undo some shenanigans done by the Media module to the media option.
if (isset($ui_definitions['field_ui:typed_relation:media'])) {
$ui_definitions['field_ui:typed_relation:media']['category'] = 'typed_relation';
$ui_definitions['field_ui:typed_relation:media']['description'] = 'A reference field with a configurable type selector.';
$ui_definitions['field_ui:typed_relation:media']['weight'] = 0;
}
// Put taxonomy term first in the option list.
if (isset($ui_definitions['field_ui:typed_relation:taxonomy_term'])) {
$ui_definitions['field_ui:typed_relation:taxonomy_term']['weight'] = -10;
}
}

/**
* Update EDTF fields from the 2012 draft to match the 2018 spec.
*/
Expand Down
1 change: 1 addition & 0 deletions css/controlled_access_terms.icons-min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldType/TypedRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* label = @Translation("Typed Relation"),
* module = "controlled_access_terms",
* category = "typed_relation",
* description = @Translation("Implements a typed relation field"),
* description = @Translation("A reference field with a configurable type selector."),
* default_formatter = "typed_relation_default",
* default_widget = "typed_relation_default",
* list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList",
Expand Down

0 comments on commit 092c704

Please sign in to comment.