Skip to content

Commit

Permalink
Add SVG icons to field types. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosiel authored Jun 26, 2024
1 parent 3938f2a commit b6b9f50
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
6 changes: 6 additions & 0 deletions controlled_access_terms.field_type_categories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
typed_relation:
label: 'Typed Relation'
description: 'A Reference field, with an associated type selected from a configurable list.'
weight: 100
libraries:
- controlled_access_terms/controlled_access_terms.icons
4 changes: 4 additions & 0 deletions controlled_access_terms.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
controlled_access_terms.icons:
css:
theme:
css/controlled_access_terms.icons-min.css: {}
34 changes: 31 additions & 3 deletions controlled_access_terms.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Controlled Access Terms stuff.
*/

use Drupal\jsonld\Normalizer\NormalizerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\controlled_access_terms\EDTFConverter;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\jsonld\Normalizer\NormalizerBase;

/**
* Implements hook_rdf_namespaces().
Expand Down Expand Up @@ -104,6 +104,34 @@ function controlled_access_terms_jsonld_field_mappings() {
];
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function controlled_access_terms_form_field_ui_field_storage_add_form_alter(&$form, &$form_state, $form_id) {
$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
12 changes: 12 additions & 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/AuthorityLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @FieldType(
* id = "authority_link",
* label = @Translation("Authority Link"),
* description = @Translation("Stores a URL string, an authority source dropdown, an optional varchar link text, and optional blob of attributes to assemble a link."),
* description = @Translation("A Link field, with an authority source selected from a configurable list."),
* default_widget = "authority_link_default",
* default_formatter = "authority_formatter_default",
* constraints = {
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Field/FieldType/TypedRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* id = "typed_relation",
* label = @Translation("Typed Relation"),
* module = "controlled_access_terms",
* category = @Translation("Typed Relation"),
* description = @Translation("Implements a typed relation field"),
* category = "typed_relation",
* 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 b6b9f50

Please sign in to comment.