Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3476285: Improve usability of Taxonomy term creations #4139

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 will be created from the 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 and check if path is 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,32 @@ 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');

// If the entity-form-display isn't found, return early.
if (empty($form_display)) {
\Drupal::logger('social_event_type')->info('The entity-form-display from Event Type taxonomy is empty.');
return;
}

// Get fields and check if path is 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,32 @@ 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');

// If the entity-form-display isn't found, return early.
if (empty($form_display)) {
\Drupal::logger('social_group_flexible_group')->info('The entity-form-display from Group Type taxonomy is empty.');
return;
}

// Get fields and check if path is 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