From c02dc407ef4fea8a9f4a9bc7be32fb98812b1077 Mon Sep 17 00:00:00 2001 From: Lily Yan <lily.yan@uwaterloo.ca> Date: Tue, 17 Nov 2020 16:24:04 -0500 Subject: [PATCH] Feature/istwcms 4183 l26yan create timeline block --- ...builder_browser_blockcat.uw_bc_content.yml | 8 +- config/install/user.role.anonymous.yml | 1 + config/install/user.role.authenticated.yml | 1 + .../user.role.uw_role_content_author.yml | 3 + .../user.role.uw_role_content_editor.yml | 3 + .../user.role.uw_role_site_manager.yml | 3 + .../uw-layout-inverted-l-right.css | 2 +- src/Access/UwNodeAccessCheck.php | 22 ++-- src/Form/UwContentModerationForm.php | 6 +- src/Plugin/Layout/Uw2ColumnLayout.php | 1 + src/Plugin/Layout/Uw3ColumnLayout.php | 1 + src/Plugin/Layout/Uw4ColumnLayout.php | 1 + src/Plugin/Layout/UwColumnLayoutBase.php | 5 +- src/Routing/UwNodeAccessRouteSubscriber.php | 46 +++---- src/Service/UWService.php | 5 +- src/Service/UWServiceInterface.php | 5 +- src/UwPermissions/UwPermissions.php | 116 ++++++++++++++---- uw_cfg_common.install | 51 ++++---- uw_cfg_common.module | 3 +- 19 files changed, 194 insertions(+), 89 deletions(-) diff --git a/config/install/layout_builder_browser.layout_builder_browser_blockcat.uw_bc_content.yml b/config/install/layout_builder_browser.layout_builder_browser_blockcat.uw_bc_content.yml index 2f22cae3..50e40679 100755 --- a/config/install/layout_builder_browser.layout_builder_browser_blockcat.uw_bc_content.yml +++ b/config/install/layout_builder_browser.layout_builder_browser_blockcat.uw_bc_content.yml @@ -35,7 +35,8 @@ blocks: weight: 0 image_path: /profiles/uw_base_profile/themes/uw_fdsu_theme_resp/images/layout_builder_browser/fullwidthimage.svg image_alt: '' - - block_id: 'inline_block:uw_cbl_image_gallery' + - + block_id: 'inline_block:uw_cbl_image_gallery' weight: 0 image_path: /profiles/uw_base_profile/themes/uw_fdsu_theme_resp/images/layout_builder_browser/imagegallery.svg image_alt: '' @@ -49,3 +50,8 @@ blocks: weight: 0 image_path: /profiles/uw_base_profile/themes/uw_fdsu_theme_resp/images/layout_builder_browser/relatedlinks.svg image_alt: '' + - + block_id: 'inline_block:uw_cbl_timeline' + weight: 0 + image_path: /profiles/uw_base_profile/themes/uw_fdsu_theme_resp/images/layout_builder_browser/timeline.svg + image_alt: '' diff --git a/config/install/user.role.anonymous.yml b/config/install/user.role.anonymous.yml index 3d01ac9d..d0dc1b6d 100644 --- a/config/install/user.role.anonymous.yml +++ b/config/install/user.role.anonymous.yml @@ -21,3 +21,4 @@ permissions: - 'view paragraph content uw_para_fact_text' - 'view paragraph content uw_para_facts_and_figures' - 'view paragraph content uw_para_ff' + - 'view paragraph content uw_para_timeline' diff --git a/config/install/user.role.authenticated.yml b/config/install/user.role.authenticated.yml index 1c4c2893..c4bf03a4 100644 --- a/config/install/user.role.authenticated.yml +++ b/config/install/user.role.authenticated.yml @@ -24,4 +24,5 @@ permissions: - 'view paragraph content uw_para_fact_text' - 'view paragraph content uw_para_facts_and_figures' - 'view paragraph content uw_para_ff' + - 'view paragraph content uw_para_timeline' - 'view the administration theme' diff --git a/config/install/user.role.uw_role_content_author.yml b/config/install/user.role.uw_role_content_author.yml index 68f877a1..438b798d 100644 --- a/config/install/user.role.uw_role_content_author.yml +++ b/config/install/user.role.uw_role_content_author.yml @@ -38,6 +38,7 @@ permissions: - 'create paragraph content uw_para_fact_text' - 'create paragraph content uw_para_facts_and_figures' - 'create paragraph content uw_para_ff' + - 'create paragraph content uw_para_timeline' - 'create terms in uw_tax_event_tags' - 'create terms in uw_tax_event_type' - 'create terms in uw_vocab_audience' @@ -63,6 +64,7 @@ permissions: - 'delete paragraph content uw_para_fact_text' - 'delete paragraph content uw_para_facts_and_figures' - 'delete paragraph content uw_para_ff' + - 'delete paragraph content uw_para_timeline' - 'edit any uw_ct_blog content' - 'edit any uw_ct_catalog_item content' - 'edit any uw_ct_event content' @@ -103,6 +105,7 @@ permissions: - 'update paragraph content uw_para_fact_text' - 'update paragraph content uw_para_facts_and_figures' - 'update paragraph content uw_para_ff' + - 'update paragraph content uw_para_timeline' - 'use uw_workflow transition needs_review' - 'use workbench access' - 'view all media revisions' diff --git a/config/install/user.role.uw_role_content_editor.yml b/config/install/user.role.uw_role_content_editor.yml index 4ba9b656..d9dac7e2 100644 --- a/config/install/user.role.uw_role_content_editor.yml +++ b/config/install/user.role.uw_role_content_editor.yml @@ -39,6 +39,7 @@ permissions: - 'create paragraph content uw_para_fact_text' - 'create paragraph content uw_para_facts_and_figures' - 'create paragraph content uw_para_ff' + - 'create paragraph content uw_para_timeline' - 'create terms in uw_tax_event_tags' - 'create terms in uw_tax_event_type' - 'create terms in uw_vocab_audience' @@ -64,6 +65,7 @@ permissions: - 'delete paragraph content uw_para_fact_text' - 'delete paragraph content uw_para_facts_and_figures' - 'delete paragraph content uw_para_ff' + - 'delete paragraph content uw_para_timeline' - 'edit any uw_ct_blog content' - 'edit any uw_ct_catalog_item content' - 'edit any uw_ct_event content' @@ -104,6 +106,7 @@ permissions: - 'update paragraph content uw_para_fact_text' - 'update paragraph content uw_para_facts_and_figures' - 'update paragraph content uw_para_ff' + - 'update paragraph content uw_para_timeline' - 'use uw_workflow transition archived' - 'use uw_workflow transition draft' - 'use uw_workflow transition needs_review' diff --git a/config/install/user.role.uw_role_site_manager.yml b/config/install/user.role.uw_role_site_manager.yml index 1b852bf7..f1ef4627 100644 --- a/config/install/user.role.uw_role_site_manager.yml +++ b/config/install/user.role.uw_role_site_manager.yml @@ -40,6 +40,7 @@ permissions: - 'create paragraph content uw_para_fact_text' - 'create paragraph content uw_para_facts_and_figures' - 'create paragraph content uw_para_ff' + - 'create paragraph content uw_para_timeline' - 'create terms in uw_tax_event_tags' - 'create terms in uw_tax_event_type' - 'create terms in uw_vocab_audience' @@ -83,6 +84,7 @@ permissions: - 'delete paragraph content uw_para_fact_text' - 'delete paragraph content uw_para_facts_and_figures' - 'delete paragraph content uw_para_ff' + - 'delete paragraph content uw_para_timeline' - 'delete terms in uw_tax_event_tags' - 'delete terms in uw_tax_event_type' - 'delete terms in uw_vocab_audience' @@ -134,6 +136,7 @@ permissions: - 'update paragraph content uw_para_fact_text' - 'update paragraph content uw_para_facts_and_figures' - 'update paragraph content uw_para_ff' + - 'update paragraph content uw_para_timeline' - 'use uw_workflow transition archived' - 'use uw_workflow transition draft' - 'use uw_workflow transition needs_review' diff --git a/layouts/uw-inverted-l-right/uw-layout-inverted-l-right.css b/layouts/uw-inverted-l-right/uw-layout-inverted-l-right.css index 54a5da7f..97b0651f 100644 --- a/layouts/uw-inverted-l-right/uw-layout-inverted-l-right.css +++ b/layouts/uw-inverted-l-right/uw-layout-inverted-l-right.css @@ -43,4 +43,4 @@ box-shadow: none; border: 1px solid #bfbfba; padding: 1rem; -} \ No newline at end of file +} diff --git a/src/Access/UwNodeAccessCheck.php b/src/Access/UwNodeAccessCheck.php index a805775f..0c190d08 100644 --- a/src/Access/UwNodeAccessCheck.php +++ b/src/Access/UwNodeAccessCheck.php @@ -17,7 +17,7 @@ class UwNodeAccessCheck implements AccessInterface { * A custom access check. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * + * Route matching. * @param \Drupal\Core\Session\AccountInterface $account * Run access checks for this account. * @@ -29,22 +29,26 @@ class UwNodeAccessCheck implements AccessInterface { // Get the node object, which is in the route match variable. $node = $route_match->getParameter('node'); - // Check if this is a sidebar content type and if the user has permission to edit the content type. - // We want to throw a 404 (NotFoundHttpException) if they do not have access. This is the case when - // a user is not logged in, and when they do not have permission to edit it. + // Check if this is a sidebar content type and if the user has permission + // to edit the content type. We want to throw a 404 (NotFoundHttpException) + // if they do not have access. This is the case when a user is not logged + // in, and when they do not have permission to edit it. if ($node && $node->bundle() == 'uw_ct_sidebar' && !$account->hasPermission('edit any uw_ct_sidebar content')) { throw new NotFoundHttpException(); } - // Check if this is a sidebar content type and if the user has permission to edit the content type. - // We want to throw a 404 (NotFoundHttpException) if they do not have access. This is the case when - // a user is not logged in, and when they do not have permission to edit it. + // Check if this is a sidebar content type and if the user has permission + // to edit the content type. We want to throw a 404 (NotFoundHttpException) + // if they do not have access. This is the case when a user is not logged + // in, and when they do not have permission to edit it. if ($node && $node->bundle() == 'uw_ct_site_footer' && !$account->hasPermission('edit any uw_ct_site_footer content')) { throw new NotFoundHttpException(); } - // We have to return some type of access, so we are going to return allowed, if they do not have access, - // the new exception is going to be thrown above. + // We have to return some type of access, so we are going to return + // allowed, if they do not have access, the new exception is going to be + // thrown above. return AccessResult::allowed(); } + } diff --git a/src/Form/UwContentModerationForm.php b/src/Form/UwContentModerationForm.php index d7923dfc..9b398b70 100644 --- a/src/Form/UwContentModerationForm.php +++ b/src/Form/UwContentModerationForm.php @@ -54,7 +54,6 @@ class UwContentModerationForm extends ConfirmFormBase { ); } - /** * {@inheritdoc} */ @@ -84,9 +83,9 @@ class UwContentModerationForm extends ConfirmFormBase { $options = ['absolute' => TRUE]; // Return the URL back to the node. - $url = Url::fromRoute('entity.node.canonical', ['node' => $this->nid], $options); + $url = Url::fromRoute('entity.node.canonical', ['node' => $this->nid], $options); - // Adding the redirect back to the node + // Adding the redirect back to the node. $form_state->setRedirectUrl($url); // Set the message that the permissions have been saved. @@ -122,4 +121,5 @@ class UwContentModerationForm extends ConfirmFormBase { // Return the URL back to the node. return Url::fromRoute('entity.node.canonical', ['node' => $this->nid], $options); } + } diff --git a/src/Plugin/Layout/Uw2ColumnLayout.php b/src/Plugin/Layout/Uw2ColumnLayout.php index e1516e8a..eb491630 100644 --- a/src/Plugin/Layout/Uw2ColumnLayout.php +++ b/src/Plugin/Layout/Uw2ColumnLayout.php @@ -34,4 +34,5 @@ class Uw2ColumnLayout extends UwColumnLayoutBase { return $form; } + } diff --git a/src/Plugin/Layout/Uw3ColumnLayout.php b/src/Plugin/Layout/Uw3ColumnLayout.php index 84171c80..308cc01f 100644 --- a/src/Plugin/Layout/Uw3ColumnLayout.php +++ b/src/Plugin/Layout/Uw3ColumnLayout.php @@ -37,4 +37,5 @@ class Uw3ColumnLayout extends UwColumnLayoutBase { return $form; } + } diff --git a/src/Plugin/Layout/Uw4ColumnLayout.php b/src/Plugin/Layout/Uw4ColumnLayout.php index de8260e5..c4c655ec 100644 --- a/src/Plugin/Layout/Uw4ColumnLayout.php +++ b/src/Plugin/Layout/Uw4ColumnLayout.php @@ -37,4 +37,5 @@ class Uw4ColumnLayout extends UwColumnLayoutBase { return $form; } + } diff --git a/src/Plugin/Layout/UwColumnLayoutBase.php b/src/Plugin/Layout/UwColumnLayoutBase.php index 299833fe..06460ba4 100644 --- a/src/Plugin/Layout/UwColumnLayoutBase.php +++ b/src/Plugin/Layout/UwColumnLayoutBase.php @@ -17,7 +17,10 @@ class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // Set the column class in the config. - $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); + $this->configuration['column_class'] = $form_state->getValue( + ['layout_settings', 'column_class'], + NULL + ); } /** diff --git a/src/Routing/UwNodeAccessRouteSubscriber.php b/src/Routing/UwNodeAccessRouteSubscriber.php index 2b7f3954..d5309c69 100644 --- a/src/Routing/UwNodeAccessRouteSubscriber.php +++ b/src/Routing/UwNodeAccessRouteSubscriber.php @@ -1,23 +1,23 @@ -<?php - -namespace Drupal\uw_cfg_common\Routing; - -use Drupal\Core\Routing\RouteSubscriberBase; -use Symfony\Component\Routing\RouteCollection; - -/** - * Listens to the dynamic route events. - */ -class UwNodeAccessRouteSubscriber extends RouteSubscriberBase { - - /** - * {@inheritdoc} - */ - protected function alterRoutes(RouteCollection $collection) { - // Change the route associated with node (/node/{nid}). - if ($route = $collection->get('entity.node.canonical')) { - $route->setRequirement('_custom_access', 'Drupal\uw_cfg_common\Access\UwNodeAccessCheck::access'); - } - } - -} \ No newline at end of file +<?php + +namespace Drupal\uw_cfg_common\Routing; + +use Drupal\Core\Routing\RouteSubscriberBase; +use Symfony\Component\Routing\RouteCollection; + +/** + * Listens to the dynamic route events. + */ +class UwNodeAccessRouteSubscriber extends RouteSubscriberBase { + + /** + * {@inheritdoc} + */ + protected function alterRoutes(RouteCollection $collection) { + // Change the route associated with node (/node/{nid}). + if ($route = $collection->get('entity.node.canonical')) { + $route->setRequirement('_custom_access', 'Drupal\uw_cfg_common\Access\UwNodeAccessCheck::access'); + } + } + +} diff --git a/src/Service/UWService.php b/src/Service/UWService.php index 821964d7..93649952 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -3,11 +3,12 @@ namespace Drupal\uw_cfg_common\Service; use Drupal\Core\Entity\EntityInterface; -use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; /** - * Class UWService + * Class UWService. + * + * UW Service that holds common functionality used by uw blocks. * * @package Drupal\uw_cfg_common\Service */ diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 360bbf85..20893c63 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -6,9 +6,9 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\node\NodeInterface; /** - * Interface UWServiceInterface + * Interface UWServiceInterface. * - * Interface that is collection of common functions used throughout custom blocks. + * Interface that is collection of common functions used in custom blocks. * * @package Drupal\uw_cfg_common\Service */ @@ -41,4 +41,5 @@ interface UWServiceInterface { * Array of variables and their values. */ public function getTeaserContent(NodeInterface $node, array $variables_to_get, string $teaser_type): array; + } diff --git a/src/UwPermissions/UwPermissions.php b/src/UwPermissions/UwPermissions.php index 0f84c2d4..7b6411f8 100644 --- a/src/UwPermissions/UwPermissions.php +++ b/src/UwPermissions/UwPermissions.php @@ -6,6 +6,8 @@ use Drupal\user\Entity\Role; /** * Class UwPermissions. + * + * UW Specific permissions. */ class UwPermissions { @@ -54,65 +56,135 @@ class UwPermissions { // Blog permissions. 'Blog' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListContentType('uw_ct_blog'), + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_blog' + ), 'Create/edit tags' => - UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_blog_tags', ['create', 'edit']), + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_blog_tags', + ['create', 'edit'] + ), 'Delete tags' => - UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_blog_tags', ['delete']), + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_blog_tags', + ['delete'] + ), ], // Catalog permissions. 'Catalog' => [ - 'Use content type' => UwPermissions::buildRolePermissionsListContentType('uw_ct_catalog_item'), - 'Create/edit audience' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_audience', ['create', 'edit']), - 'Delete audience' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_audience', ['delete']), - 'Create/edit categories' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_catalog_categories', ['create', 'edit']), - 'Delete categories' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_catalog_categories', ['delete']), - 'Create/edit catalogs' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_catalogs', ['create', 'edit']), - 'Delete catalogs' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_catalogs', ['delete']), + 'Use content type' => + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_catalog_item' + ), + 'Create/edit audience' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_audience', + ['create', 'edit'] + ), + 'Delete audience' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_audience', + ['delete'] + ), + 'Create/edit categories' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_catalog_categories', + ['create', 'edit'] + ), + 'Delete categories' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_catalog_categories', + ['delete'] + ), + 'Create/edit catalogs' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_catalogs', + ['create', 'edit'] + ), + 'Delete catalogs' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_catalogs', + ['delete'] + ), ], // Event permissions. 'Event' => [ - 'Use content type' => UwPermissions::buildRolePermissionsListContentType('uw_ct_event'), - 'Create/edit tags' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_tax_event_tags', ['create', 'edit']), - 'Delete tags' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_tax_event_tags', ['delete']), - 'Create/edit types' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_tax_event_type', ['create', 'edit']), - 'Delete types' => UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_tax_event_type', ['delete']), + 'Use content type' => + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_event' + ), + 'Create/edit tags' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_tax_event_tags', + ['create', 'edit'] + ), + 'Delete tags' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_tax_event_tags', + ['delete'] + ), + 'Create/edit types' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_tax_event_type', + ['create', 'edit'] + ), + 'Delete types' => + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_tax_event_type', + ['delete'] + ), ], // News permissions. 'News' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListContentType('uw_ct_news_item'), + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_news_item' + ), 'Create/edit tags' => - UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_news_tags', ['create', 'edit']), + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_news_tags', + ['create', 'edit'] + ), 'Delete tags' => - UwPermissions::buildRolePermissionsListTaxonomyTerm('uw_vocab_news_tags', ['delete']), + UwPermissions::buildRolePermissionsListTaxonomyTerm( + 'uw_vocab_news_tags', + ['delete'] + ), ], // Sidebar permissions. 'Sidebar' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListContentType('uw_ct_sidebar'), + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_sidebar' + ), ], // Site footer permissions. 'Site footer' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListContentType('uw_ct_site_footer'), + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_site_footer' + ), ], // Special alert permissions. 'Special alert' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListCustom('administer special alert'), + UwPermissions::buildRolePermissionsListCustom( + 'administer special alert' + ), ], // Web page permissions. 'Web page' => [ 'Use content type' => - UwPermissions::buildRolePermissionsListContentType('uw_ct_web_page'), + UwPermissions::buildRolePermissionsListContentType( + 'uw_ct_web_page' + ), ], ]; diff --git a/uw_cfg_common.install b/uw_cfg_common.install index 56f436d8..b427141f 100644 --- a/uw_cfg_common.install +++ b/uw_cfg_common.install @@ -5,6 +5,7 @@ * Install, update and uninstall for Configuration of all common WCMS. */ +use Drupal\taxonomy\Entity\Term; use Drupal\uw_cfg_common\UwPermissions\UwPermissions; /** @@ -53,7 +54,7 @@ function uw_cfg_common_install() { 'Site manager', 'Content author', 'Content editor', - ], + ], 'Delete catalogs' => [ 'Site manager', ], @@ -137,29 +138,29 @@ function uw_cfg_common_install() { 'Future undergraduate students', 'Future graduate students', ], - 'Faculty', - 'Staff', - 'Alumni', - 'Parents', - 'Donors | Friends | Supporters', - 'Employers', - 'International', - 'Media', + 'Faculty' => 'Faculty', + 'Staff' => 'Staff', + 'Alumni' => 'Alumni', + 'Parents' => 'Parents', + 'Donors | Friends | Supporters' => 'Donors | Friends | Supporters', + 'Employers' => 'Employers', + 'International' => 'International', + 'Media' => 'Media', ]; $weight = 0; foreach ($terms as $key => $term) { - if (is_array($term)) { - $parent = _uw_cfg_common_create_term($key, 'uw_vocab_audience', $weight, []); + if (is_array($term)) { + $parent = _uw_cfg_common_create_term($key, 'uw_vocab_audience', $weight, []); - foreach ($term as $child) { - _uw_cfg_common_create_term($child, 'uw_vocab_audience', $weight, [$parent]); - } - } - else { - _uw_cfg_common_create_term($term, 'uw_vocab_audience', $weight, []); - } - $weight++; + foreach ($term as $child) { + _uw_cfg_common_create_term($child, 'uw_vocab_audience', $weight, [$parent]); + } + } + else { + _uw_cfg_common_create_term($term, 'uw_vocab_audience', $weight, []); + } + $weight++; } } @@ -179,20 +180,24 @@ function uw_cfg_common_install() { * $term_id = _nodemaker_term_create('My Term', 'my_vocab', 0, [999]); * @endcode * - * @param string $term + * @param string $taxonomy_name * - Term Name. - * @param string $vocabulary + * @param string $vocab_machine_name * - System id of the vocabulary term will be added to. - * @param array $parent + * @param string|int $weight + * - Taxonomy term weight. + * @param array $parent_tid * - Array of term ids to be assigned as parent. * * @return int|null * - Returns the term id of the created term on success, null on failure. + * + * @throws \Drupal\Core\Entity\EntityStorageException */ function _uw_cfg_common_create_term($taxonomy_name, $vocab_machine_name, $weight, array $parent_tid = []) { // Create the taxonomy term. - $new_term = Drupal\taxonomy\Entity\Term::create([ + $new_term = Term::create([ 'name' => $taxonomy_name, 'vid' => $vocab_machine_name, 'parent' => $parent_tid, diff --git a/uw_cfg_common.module b/uw_cfg_common.module index a632c42e..10a21fb1 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -201,7 +201,7 @@ function uw_cfg_common_preprocess_node(&$variables) { $access_result = $plugin_block->access(\Drupal::currentUser()); // Return empty render array if user doesn't have access. - // $access_result can be boolean or an AccessResult class + // $access_result can be boolean or an AccessResult class. if (is_object($access_result) && $access_result->isForbidden() || is_bool($access_result) && !$access_result) { return []; } @@ -211,4 +211,3 @@ function uw_cfg_common_preprocess_node(&$variables) { $variables['uw_content_moderation_form'] = $render; } } - -- GitLab