Skip to content

Commit

Permalink
Hide Path field for Taxonomies to improve the user-experience.
Browse files Browse the repository at this point in the history
Some taxonomies doesn't have entity-form-display created, so a logic is created to check it, after this validation the entity-form-display is created or updated.
  • Loading branch information
vcsvinicius committed Oct 28, 2024
1 parent 9ab2447 commit a74b63e
Show file tree
Hide file tree
Showing 15 changed files with 547 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.report_reasons
module:
- text
id: taxonomy_term.report_reasons.default
targetEntityType: taxonomy_term
bundle: report_reasons
mode: default
content:
description:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
weight: 3
region: content
settings:
display_label: true
third_party_settings: { }
hidden:
path: true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Entity\EntityStorageException;
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\Yaml\Yaml;

/**
* Implements hook_install().
Expand Down Expand Up @@ -103,3 +104,44 @@ function social_content_report_update_130001(): void {
];
user_role_grant_permissions('sitemanager', $permissions);
}

/**
* Create entity-form-display or hidden path field from Report Reasons taxonomy.
*/
function social_content_report_update_130002(): void {
$storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
$form_display = $storage->load('taxonomy_term.report_reasons.default');

// When entity-form-display isn't be created,
// it'll create from install folder.
if (empty($form_display)) {
// Get file from install folder and check if it exists.
$config_file = \Drupal::service('extension.list.module')->getPath('social_content_report') . '/config/install/core.entity_form_display.taxonomy_term.report_reasons.default.yml';
if (file_exists($config_file) === FALSE) {
\Drupal::logger('social_content_report')->error('Configuration file for entity-form-display "report_reasons" not found.');
return;
}

// Apply the configuration to create entity-form-display.
$view_config = Yaml::parseFile($config_file);
\Drupal::configFactory()->getEditable('core.entity_form_display.taxonomy_term.report_reasons.default')
->setData($view_config)
->save();
}
else {
// Get fields from entity-form-display and check if path already be hidden.
$hidden = $form_display->get('hidden');
$content = $form_display->get('content');
if (in_array('path', array_keys($hidden))) {
\Drupal::logger('social_content_report')->info('The path field already is hidden on Report Reasons taxonomy.');
return;
}

// Manipulate path field to be hidden and save.
$hidden['path'] = TRUE;
unset($content['path']);
$form_display->set('hidden', $hidden)
->set('content', $content)
->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ content:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 2
region: content
settings: { }
third_party_settings: { }
hidden: { }
hidden:
path: true
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,26 @@ function social_event_type_update_last_removed() : int {
function social_event_type_update_130001(): void {
user_role_grant_permissions('sitemanager', ['create terms in event_types']);
}

/**
* Hidden path from Event Type taxonomy.
*/
function social_event_type_update_130002(): void {
$storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
$form_display = $storage->load('taxonomy_term.event_types.default');

// Get fields from entity-form-display and check if path already be hidden.
$hidden = $form_display->get('hidden');
$content = $form_display->get('content');
if (in_array('path', array_keys($hidden))) {
\Drupal::logger('social_event_type')->info('The path field already is hidden on Profile Tag taxonomy.');
return;
}

// Manipulate path field to be hidden and save.
$hidden['path'] = TRUE;
unset($content['path']);
$form_display->set('hidden', $hidden)
->set('content', $content)
->save();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ content:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 2
region: content
settings: { }
third_party_settings: { }
hidden: { }
hidden:
path: true
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,26 @@ function social_group_flexible_group_update_130005() : void {
\Drupal::service('module_installer')->install(['social_email_broadcast']);
}
}

/**
* Hidden path from Group Type taxonomy.
*/
function social_group_flexible_group_update_130006(): void {
$storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
$form_display = $storage->load('taxonomy_term.group_type.default');

// Get fields from entity-form-display and check if path already be hidden.
$hidden = $form_display->get('hidden');
$content = $form_display->get('content');
if (in_array('path', array_keys($hidden))) {
\Drupal::logger('social_group_flexible_group')->info('The path field already is hidden on Group Type taxonomy.');
return;
}

// Manipulate path field to be hidden and save.
$hidden['path'] = TRUE;
unset($content['path']);
$form_display->set('hidden', $hidden)
->set('content', $content)
->save();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.expertise
module:
- text
id: taxonomy_term.expertise.default
targetEntityType: taxonomy_term
bundle: expertise
mode: default
content:
description:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
weight: 3
region: content
settings:
display_label: true
third_party_settings: { }
hidden:
path: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.interests
module:
- text
id: taxonomy_term.interests.default
targetEntityType: taxonomy_term
bundle: interests
mode: default
content:
description:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
weight: 3
region: content
settings:
display_label: true
third_party_settings: { }
hidden:
path: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.profile_tag
module:
- text
id: taxonomy_term.profile_tag.default
targetEntityType: taxonomy_term
bundle: profile_tag
mode: default
content:
description:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
weight: 3
region: content
settings:
display_label: true
third_party_settings: { }
hidden:
path: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.nationality
module:
- text
id: taxonomy_term.nationality.default
targetEntityType: taxonomy_term
bundle: nationality
mode: default
content:
description:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
weight: 3
region: content
settings:
display_label: true
third_party_settings: { }
hidden:
path: true
Loading

0 comments on commit a74b63e

Please sign in to comment.