-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfc66a5
commit 2b30092
Showing
9 changed files
with
359 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
config/install/field.storage.node.field_content_category.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- field_permissions | ||
- node | ||
- taxonomy | ||
third_party_settings: | ||
field_permissions: | ||
permission_type: public | ||
id: node.field_content_category | ||
field_name: field_content_category | ||
entity_type: node | ||
type: entity_reference | ||
settings: | ||
target_type: taxonomy_term | ||
module: core | ||
locked: false | ||
cardinality: -1 | ||
translatable: true | ||
indexes: { } | ||
persist_with_no_fields: false | ||
custom_storage: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
langcode: en | ||
status: true | ||
dependencies: { } | ||
name: 'Content category' | ||
vid: content_category | ||
description: 'Categories assigned to all content to assist with filtering in content collection and search' | ||
weight: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* This file supports other modules in their hook_update_N. | ||
*/ | ||
|
||
use Drupal\Core\Entity\Entity\EntityFormDisplay; | ||
use Drupal\field\Entity\FieldConfig; | ||
use Drupal\taxonomy\Entity\Term; | ||
|
||
/** | ||
* Set default values for the field_content_category field. | ||
* | ||
* @param string $bundle | ||
* The bundle of the entity. | ||
* @param mixed $term_names | ||
* A single term name or an array of term names to set as default values. | ||
*/ | ||
function _tide_core_field_content_category_default_value(string $bundle, $term_names) { | ||
// Ensure $term_names is always an array. | ||
if (!is_array($term_names)) { | ||
$term_names = [$term_names]; | ||
} | ||
|
||
$default_values = []; | ||
|
||
foreach ($term_names as $term_name) { | ||
$query = \Drupal::entityQuery('taxonomy_term') | ||
->condition('name', $term_name) | ||
->condition('vid', 'content_category') | ||
->condition('parent', 0, '<>') | ||
->accessCheck(TRUE); | ||
|
||
$results = $query->execute(); | ||
if (!empty($results)) { | ||
$tid = reset($results); | ||
$uuid = Term::load($tid)->uuid(); | ||
if (!empty($uuid)) { | ||
$default_values[] = ['target_uuid' => $uuid]; | ||
} | ||
} | ||
} | ||
|
||
if (!empty($default_values)) { | ||
/** @var \Drupal\field\Entity\FieldConfig $config */ | ||
$config = FieldConfig::loadByName('node', $bundle, 'field_content_category'); | ||
$config->set('default_value', $default_values)->save(); | ||
} | ||
} | ||
|
||
/** | ||
* Set form display for field_content_category field. | ||
*/ | ||
function _tide_core_content_category_form_display(string $bundle) { | ||
$entity_form_display = EntityFormDisplay::load('node.' . $bundle . '.default'); | ||
$detail = $entity_form_display->getComponent('field_tags'); | ||
$weight = $detail['weight']; | ||
$content = [ | ||
"type" => "term_reference_tree", | ||
"weight" => $weight + 1, | ||
"region" => "content", | ||
"settings" => [ | ||
"start_minimized" => TRUE, | ||
"leaves_only" => TRUE, | ||
"select_parents" => FALSE, | ||
"cascading_selection" => 0, | ||
"max_depth" => 0, | ||
], | ||
"third_party_settings" => [], | ||
]; | ||
$field_content_category_component = $entity_form_display->getComponent('field_content_category'); | ||
if ($field_content_category_component === NULL) { | ||
$entity_form_display->setComponent('field_content_category', $content)->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.