From 23c19397cded080a03a5eed7ecdf0bbdf166758f Mon Sep 17 00:00:00 2001 From: vincent-gao Date: Fri, 17 Nov 2023 10:04:48 +1100 Subject: [PATCH] feat: drupal 10 compatibility update (#135) * feat: Drupal 10 update. --------- Co-authored-by: Md Nadim Hossain --- composer.json | 16 +- .../tide_site_preview.info.yml | 2 +- .../tide_site_preview.install | 28 - .../tide_site_simple_sitemap.install | 17 - .../TideSiteRequestEventSubscriber.php | 22 +- src/Plugin/Linkit/Substitution/Canonical.php | 2 +- tide_site.info.yml | 2 +- tide_site.install | 723 ------------------ tide_site.module | 6 +- 9 files changed, 29 insertions(+), 789 deletions(-) diff --git a/composer.json b/composer.json index 4565c135..500afb4c 100644 --- a/composer.json +++ b/composer.json @@ -4,18 +4,24 @@ "type": "drupal-module", "license": "GPL-2.0-or-later", "require": { - "dpc-sdp/tide_core": "^3.2.5", - "dpc-sdp/tide_media": "^3.0.8", - "drupal/create_menus_permission": "^1.0", + "dpc-sdp/tide_core": "^4.0.0", + "dpc-sdp/tide_media": "^4.0.0", + "drupal/create_menus_permission": "dev-drupal_10_compatibility", "drupal/key_value_field": "^1.3" }, "suggest": { - "dpc-sdp/tide_api:^3.0.0": "Allows to use Drupal in headless mode" + "dpc-sdp/tide_api:^4.0.0": "Allows to use Drupal in headless mode" }, "repositories": { "drupal": { "type": "composer", - "url": "https://packages.drupal.org/8" + "url": "https://packages.drupal.org/10", + "exclude": ["drupal/create_menus_permission"] + }, + "drupal/create_menus_permission": { + "type": "vcs", + "no-api": true, + "url": "https://github.com/dpc-sdp/create_menus_permission.git" } }, "extra": { diff --git a/modules/tide_site_preview/tide_site_preview.info.yml b/modules/tide_site_preview/tide_site_preview.info.yml index 0cc3b1c3..030094a5 100644 --- a/modules/tide_site_preview/tide_site_preview.info.yml +++ b/modules/tide_site_preview/tide_site_preview.info.yml @@ -2,7 +2,7 @@ name: 'Tide Site - Preview links' description: Provides frontend preview links for content managed with Tide Site. type: module package: Tide -core_version_requirement: ^8.9 || ^9 +core_version_requirement: ^9 || ^10 dependencies: - dpc-sdp:tide_site - dpc-sdp:tide_api diff --git a/modules/tide_site_preview/tide_site_preview.install b/modules/tide_site_preview/tide_site_preview.install index 8a77acf3..8ae5e4e7 100644 --- a/modules/tide_site_preview/tide_site_preview.install +++ b/modules/tide_site_preview/tide_site_preview.install @@ -5,7 +5,6 @@ * Tide Site install file. */ -use Drupal\block\Entity\Block; use Drupal\user\Entity\Role; /** @@ -22,30 +21,3 @@ function tide_site_preview_install() { } } } - -/** - * Remove block.block.seven_tide_site_preview_links. - */ -function tide_site_preview_update_8001() { - $block = Block::load('seven_tide_site_preview_links'); - if ($block !== NULL) { - $block->delete(); - } -} - -/** - * Install block.block.claro_tide_site_preview_links. - */ -function tide_site_preview_update_8002() { - \Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers'); - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site_preview') . '/config/optional']; - $storage = \Drupal::entityTypeManager()->getStorage('block'); - $id = 'claro_tide_site_preview_links'; - $config_entity = $storage->load($id); - if ($config_entity !== NULL) { - $storage->delete([$config_entity]); - } - $config_read = _tide_read_config('block.block.claro_tide_site_preview_links', $config_location, FALSE); - $new_config_entity = $storage->createFromStorageRecord($config_read); - $new_config_entity->save(); -} diff --git a/modules/tide_site_simple_sitemap/tide_site_simple_sitemap.install b/modules/tide_site_simple_sitemap/tide_site_simple_sitemap.install index 8d5f7cf8..3c111193 100644 --- a/modules/tide_site_simple_sitemap/tide_site_simple_sitemap.install +++ b/modules/tide_site_simple_sitemap/tide_site_simple_sitemap.install @@ -15,13 +15,6 @@ function tide_site_simple_sitemap_install($is_syncing) { _update_settings(); } -/** - * Updates bundle settings. - */ -function tide_site_simple_sitemap_update_8008(&$sandbox) { - _update_settings(); -} - /** * Update for sitemap 4.x. */ @@ -83,13 +76,3 @@ function _update_settings() { } } } - -/** - * Removes simple_sitemap_site table. - */ -function tide_site_simple_sitemap_update_8009() { - $hasTable = \Drupal::database()->schema()->tableExists('simple_sitemap_site'); - if ($hasTable === TRUE) { - \Drupal::database()->schema()->dropTable('simple_sitemap_site'); - } -} diff --git a/src/EventSubscriber/TideSiteRequestEventSubscriber.php b/src/EventSubscriber/TideSiteRequestEventSubscriber.php index 22209838..5e6e8548 100644 --- a/src/EventSubscriber/TideSiteRequestEventSubscriber.php +++ b/src/EventSubscriber/TideSiteRequestEventSubscriber.php @@ -5,20 +5,20 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\jsonapi\Routing\Routes; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType; use Drupal\tide_site\TideSiteFields; use Drupal\tide_site\TideSiteHelper; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -86,13 +86,13 @@ public static function getSubscribedEvents() { /** * Add Site filter to the request of JSON API controller. * - * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The event. * * @see \Symfony\Component\HttpKernel\HttpKernel::handleRaw() * @see \Drupal\jsonapi\Controller\RequestHandler::handle() */ - public function onRequestAddSiteFilter(GetResponseEvent $event) { + public function onRequestAddSiteFilter(RequestEvent $event) { if (!$this->jsonApiEnabled) { return; } @@ -214,16 +214,16 @@ public function onRequestAddSiteFilter(GetResponseEvent $event) { /** * Add Site to cache context and tags of JSON API response. * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * The event object. */ - public function onResponseAddSiteFilterCacheContext(FilterResponseEvent $event) { + public function onResponseAddSiteFilterCacheContext(ResponseEvent $event) { $response = $event->getResponse(); if (!$response instanceof CacheableResponseInterface) { return; } - $site_id = $event->getRequest()->query->get('site'); + $site_id = $event->getRequest()->query->all()['site'] ?? []; if ($site_id) { $context = $response->getCacheableMetadata()->getCacheContexts(); $context = Cache::mergeContexts($context, ['url.query_args:site']); @@ -246,7 +246,7 @@ public function onResponseAddSiteFilterCacheContext(FilterResponseEvent $event) * The Resource type. */ protected function setSiteFilterToJsonApi(Request $request, array $site_filter, ConfigurableResourceType $resource_type) { - $filter = $request->query->get('filter', []); + $filter = $request->query->all()['filter'] ?? []; $filter['site'] = $site_filter; $request->query->set('filter', $filter); } @@ -254,14 +254,14 @@ protected function setSiteFilterToJsonApi(Request $request, array $site_filter, /** * Create a JSON Response for error message. * - * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The event. * @param string $error_message * The error message. * @param int $code * The error code, default to 400. */ - protected function setEventErrorResponse(GetResponseEvent $event, $error_message, $code = Response::HTTP_BAD_REQUEST) { + protected function setEventErrorResponse(RequestEvent $event, $error_message, $code = Response::HTTP_BAD_REQUEST) { $json_response = [ 'links' => [ 'self' => [ diff --git a/src/Plugin/Linkit/Substitution/Canonical.php b/src/Plugin/Linkit/Substitution/Canonical.php index b98d7cac..c6eb2ad5 100644 --- a/src/Plugin/Linkit/Substitution/Canonical.php +++ b/src/Plugin/Linkit/Substitution/Canonical.php @@ -69,7 +69,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function getUrl(EntityInterface $entity) { /** @var \Drupal\Core\GeneratedUrl $url */ - $url = parent::getUrl($entity); + $url = parent::getUrl($entity)->toString(TRUE); // Remove the site prefix from path alias when responding from // JSONAPI entity resource with site parameter. diff --git a/tide_site.info.yml b/tide_site.info.yml index 0c0e54d9..d2739c88 100644 --- a/tide_site.info.yml +++ b/tide_site.info.yml @@ -2,7 +2,7 @@ name: 'Tide site' description: 'Functionality to allow post content to multiple sites and sections.' type: module package: Tide -core_version_requirement: ^8.9 || ^9 +core_version_requirement: ^9.5 || ^10 dependencies: - drupal:field - drupal:field_ui diff --git a/tide_site.install b/tide_site.install index 9d8b1dad..83348050 100644 --- a/tide_site.install +++ b/tide_site.install @@ -5,13 +5,6 @@ * Install file for tide_site. */ -use Drupal\Core\Config\FileStorage; -use Drupal\Core\Entity\Display\EntityFormDisplayInterface; -use Drupal\Core\Site\Settings; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldStorageConfig; -use Drupal\taxonomy\TaxonomyPermissions; - /** * Implements hook_install(). */ @@ -24,719 +17,3 @@ function tide_site_install() { } } } - -/** - * Implements hook_update_dependencies(). - */ -function tide_site_update_dependencies() { - $dependencies = []; - $dependencies['tide_site'][8002] = ['tide_core' => 8003]; - $dependencies['tide_site'][8004] = ['system' => 8805]; - - return $dependencies; -} - -/** - * Add existing content types to field_site_homepage. - */ -function tide_site_update_8001() { - /** @var \Drupal\tide_site\TideSiteFields $helper */ - $helper = \Drupal::service('tide_site.fields'); - - $info = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo(); - foreach ($info as $type => $bundles) { - if ($type == 'node') { - $helper->addContentTypesToSiteHomepageField(array_keys($bundles)); - } - } -} - -/** - * Generate path alias for existing content. - */ -function tide_site_update_8002(&$sandbox) { - $nids = []; - $nodes = \Drupal::entityQuery('node')->execute(); - foreach ($nodes as $nid) { - $nids[] = $nid; - } - - // Use the sandbox to store the information needed to track progression. - if (!isset($sandbox['current'])) { - $sandbox['current'] = 0; - $sandbox['max'] = count($nids); - } - - /** @var \Drupal\pathauto\PathautoGenerator $generator */ - $generator = \Drupal::service('pathauto.generator'); - $entity_storage = \Drupal::entityTypeManager()->getStorage('node'); - - $limit = 20; - $nids = array_slice($nids, $sandbox['current'], $limit); - foreach ($nids as $nid) { - $node = $entity_storage->load($nid); - $generator->updateEntityAlias($node, 'create', ['force' => TRUE]); - // Update the progress. - $sandbox['current']++; - } - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']); - - if ($sandbox['#finished'] >= 1) { - \Drupal::messenger()->addStatus(t('The batch URL Alias update is finished.')); - } -} - -/** - * Import summary_contents and summary_media views. - */ -function tide_site_update_8003() { - $view = 'views.view.summary_contents'; - $config_path = \Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install'; - $source = new FileStorage($config_path); - $config_storage = \Drupal::service('config.storage'); - $config_storage->write($view, $source->read($view)); -} - -/** - * Fixes node_delete_action plugin issue. - */ -function tide_site_update_8004() { - $config_factory = \Drupal::configFactory(); - $config = $config_factory->getEditable('system.action.node_delete_action'); - $config->set('plugin', 'entity:delete_action:node'); - $config->save(); -} - -/** - * Update og:image metatag for taxonomy_term:sites. - */ -function tide_site_update_8005() { - module_load_include('inc', 'tide_core', 'includes/helpers'); - $module_path = \Drupal::service('extension.list.module')->getPath('tide_site'); - $config_location = [$module_path . '/config/install']; - _tide_import_single_config('field.storage.taxonomy_term.field_site_og_image', $config_location); - _tide_import_single_config('field.field.taxonomy_term.sites.field_site_og_image', $config_location); - - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */ - $entity_form_display = \Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_site_og_image', [ - 'weight' => 11, - 'settings' => [ - 'entity_browser' => 'tide_image_browser', - 'field_widget_display' => 'rendered_entity', - 'field_widget_display_settings' => [ - 'view_mode' => 'media_browser_preview', - ], - 'field_widget_edit' => TRUE, - 'field_widget_remove' => TRUE, - 'selection_mode' => 'selection_append', - 'field_widget_replace' => FALSE, - 'open' => FALSE, - ], - 'third_party_settings' => [], - 'type' => 'entity_browser_entity_reference', - 'region' => 'content', - ]); - $entity_form_display->save(); - } - - $metatag = \Drupal::configFactory()->getEditable('metatag.metatag_defaults.taxonomy_term__sites'); - if ($metatag->isNew()) { - $config_location = [$module_path . '/config/optional']; - _tide_import_single_config('metatag.metatag_defaults.taxonomy_term__sites', $config_location); - } - else { - $og_image = $metatag->get('tags.og_image'); - if (!$og_image) { - $metatag->set('tags.og_image', '[term:field_site_og_image:entity:field_media_image:entity:url]') - ->save(); - } - } -} - -/** - * Add Prominence of Acknowledgement of Country field. - */ -function tide_site_update_8006() { - module_load_include('inc', 'tide_core', 'includes/helpers'); - $module_path = \Drupal::service('extension.list.module')->getPath('tide_site'); - $config_location = [$module_path . '/config/install']; - _tide_import_single_config('field.storage.taxonomy_term.field_prominence_ack_to_country', $config_location); - _tide_import_single_config('field.field.taxonomy_term.sites.field_prominence_ack_to_country', $config_location); - - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */ - $entity_form_display = \Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_prominence_ack_to_country', [ - 'weight' => 11, - 'settings' => [ - 'row' => 5, - 'placeholder' => '', - ], - 'third_party_settings' => [], - 'type' => 'string_textarea', - 'region' => 'content', - ]); - - $og_image = $entity_form_display->getComponent('field_site_og_image'); - if ($og_image) { - $og_image['weight'] = 12; - $entity_form_display->setComponent('field_site_og_image', $og_image); - } - - $entity_form_display->save(); - } -} - -/** - * Change field_media_site to be required. - */ -function tide_site_update_8007() { - $entity_type = 'media'; - $field_name = 'field_media_site'; - $field_storage = FieldStorageConfig::loadByName($entity_type, $field_name); - if ($field_storage) { - foreach ($field_storage->getBundles() as $bundle) { - $field = FieldConfig::loadByName($entity_type, $bundle, $field_name); - if ($field) { - $field->set('required', TRUE); - $field->save(); - } - } - } -} - -/** - * Disable default content view. - */ -function tide_site_update_8008() { - $view_id = 'content'; - $view = \Drupal::entityTypeManager()->getStorage('view')->load($view_id); - if ($view) { - $view->setStatus(FALSE)->save(); - } -} - -/** - * Disable summary_contents view. - */ -function tide_site_update_8009() { - $view_id = 'summary_contents'; - $view = \Drupal::entityTypeManager()->getStorage('view')->load($view_id); - if ($view) { - $view->setStatus(FALSE)->save(); - - $view->delete(); - $config = \Drupal::configFactory() - ->getEditable('views.view.summary_contents'); - if ($config) { - $config->delete(); - } - } -} - -/** - * Import summary_contents_filters. - */ -function tide_site_update_8010() { - $view = 'views.view.summary_contents_filters'; - $config_path = \Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install'; - $source = new FileStorage($config_path); - $config_storage = \Drupal::service('config.storage'); - $config_storage->write($view, $source->read($view)); -} - -/** - * Update approver and site_admin roles permissions. - * - * 1. approver and site_admin cannot delete sites terms. - * 2. revoke `administer taxonomy` permission. - * 3. assign `access taxonomy overview` permission. - */ -function tide_site_update_8011() { - $roles = ['approver', 'site_admin']; - $taxonomy_permissions = new TaxonomyPermissions(\Drupal::entityManager()); - foreach ($roles as $role_id) { - $assigned_permissions = ['access taxonomy overview']; - foreach ($taxonomy_permissions->permissions() as $permission => $details) { - $exploded = explode(' ', trim($permission)); - $vocabulary = $exploded[count($exploded) - 1]; - if ($exploded[0] == 'delete' && $vocabulary == 'sites') { - continue; - } - $assigned_permissions[] = $permission; - } - user_role_revoke_permissions($role_id, ['administer taxonomy']); - user_role_grant_permissions($role_id, $assigned_permissions); - } -} - -/** - * Enable alt field for site logo. - */ -function tide_site_update_8012() { - $entity_type = 'taxonomy_term'; - $bundle = 'sites'; - $field_name = 'field_site_logo'; - $field = FieldConfig::loadByName($entity_type, $bundle, $field_name); - if ($field) { - $field->setSetting('alt_field', TRUE)->save(); - } -} - -/** - * Disable content moderation view. - */ -function tide_site_update_8014() { - $view = 'tide_core_moderated_content_filters'; - \Drupal::entityTypeManager()->getStorage('view') - ->load($view) - ->setStatus(FALSE) - ->save(); - - \Drupal::entityTypeManager()->getStorage('view')->load($view)->delete(); - \Drupal::configFactory()->getEditable('views.view.tide_core_moderated_content_filters')->delete(); -} - -/** - * Import content moderation view. - */ -function tide_site_update_8015() { - $view = 'views.view.tide_site_moderated_content_filters'; - $config_path = \Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install'; - $source = new FileStorage($config_path); - $config_storage = \Drupal::service('config.storage'); - $config_storage->write($view, $source->read($view)); -} - -/** - * Import summary content filters view. - */ -function tide_site_update_8016() { - $view = 'views.view.summary_contents_filters'; - $config_path = \Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install'; - $source = new FileStorage($config_path); - $config_storage = \Drupal::service('config.storage'); - $config_storage->write($view, $source->read($view)); -} - -/** - * Changes display of dates in CMS to Australian style DD/MM/YYYY. - */ -function tide_site_update_8017() { - // Changes content view. - $summary_contents_view = \Drupal::configFactory() - ->getEditable('views.view.summary_contents_filters'); - $display = $summary_contents_view->get('display'); - $display['default']['display_options']['fields']['changed_1']['settings']['custom_date_format'] = 'd/m/Y - H:i'; - $summary_contents_view->set('display', $display)->save(); -} - -/** - * Enable SVG filetype for site logo. - */ -function tide_site_update_8018() { - $entity_type = 'taxonomy_term'; - $bundle = 'sites'; - $field_name = 'field_site_logo'; - $field = FieldConfig::loadByName($entity_type, $bundle, $field_name); - if ($field) { - $field->setSetting('file_extensions', 'png gif jpg jpeg svg')->save(); - } -} - -/** - * Add a new optional Twitter Image on the Site Taxonomy. - */ -function tide_site_update_8019() { - - $config_location = [Settings::get('config_sync_directory', FALSE)]; - module_load_include('inc', 'tide_core', 'includes/helpers'); - try { - _tide_read_config('field.storage.taxonomy_term.field_site_twitter_image', $config_location, TRUE); - } - catch (Exception $ex) { - if ($ex->getMessage() == 'Configuration does not exist in any provided locations') { - - $configs = [ - 'field.storage.taxonomy_term.field_site_twitter_image' => 'field_storage_config', - 'field.field.taxonomy_term.sites.field_site_twitter_image' => 'field_config', - ]; - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install']; - // Check if field already exported to config/sync. - foreach ($configs as $config => $type) { - $config_read = _tide_read_config($config, $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage($type); - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - - // Adding the field to display form. - $entity_form_display = Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_site_twitter_image', [ - 'weight' => 13, - 'settings' => [ - 'entity_browser' => 'tide_image_browser', - 'field_widget_display' => 'rendered_entity', - 'field_widget_display_settings' => [ - 'view_mode' => 'media_browser_preview', - ], - 'field_widget_edit' => 'true', - 'field_widget_remove' => 'true', - 'selection_mode' => 'selection_append', - 'field_widget_replace' => 'false', - 'open' => 'false', - ], - 'third_party_settings' => [], - 'type' => 'entity_browser_entity_reference', - 'region' => 'content', - ]); - } - $entity_form_display->save(); - - // Adding the field to display view. - $entity_view_display = Drupal::entityTypeManager() - ->getStorage('entity_view_display') - ->load('taxonomy_term.sites.default'); - if ($entity_view_display) { - $entity_view_display->setComponent('field_site_twitter_image', [ - 'weight' => 11, - 'label' => 'above', - 'settings' => [ - 'view_mode' => 'default', - 'link' => FALSE, - ], - 'third_party_settings' => [], - 'region' => 'content', - ]); - } - $entity_view_display->save(); - } - } -} - -/** - * Create sites social media link field. - */ -function tide_site_update_8020(&$sandbox) { - $configs = [ - 'field.storage.taxonomy_term.field_site_social_links' => 'field_storage_config', - 'field.field.taxonomy_term.sites.field_site_social_links' => 'field_config', - ]; - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install']; - // Check if field already exported to config/sync. - foreach ($configs as $config => $type) { - $config_read = _tide_read_config($config, $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage($type); - $id = substr($config, strrpos($config, '.') + 1); - if ($storage->load($id) == NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - } - - $entity_form_display = \Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - - if ($entity_form_display instanceof EntityFormDisplayInterface) { - $entity_form_display->setComponent('field_site_social_links', [ - 'weight' => 14, - 'settings' => [ - 'placeholder_url' => 'https://example.com/Social', - 'placeholder_title' => 'Example Social', - ], - 'third_party_settings' => [ - 'maxlength' => [ - 'maxlength_js' => 35, - 'maxlength_js_label' => 'Link text limited to @limit characters, remaining: @remaining', - ], - ], - 'type' => 'link_default', - 'region' => 'content', - ]); - - $entity_form_display->save(); - } - -} - -/** - * Install "Create Menus Permission" module. - */ -function tide_site_update_8021() { - $module = 'create_menus_permission'; - if (!\Drupal::moduleHandler()->moduleExists($module)) { - \Drupal::service('module_installer')->install([$module]); - } -} - -/** - * Display only distinct results. - */ -function tide_site_update_8022() { - // Getting the updated query option from install dir. - module_load_include('inc', 'tide_core', 'includes/helpers'); - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install']; - $config = 'views.view.summary_contents_filters'; - $config_read = _tide_read_config($config, $config_location, FALSE); - $query = $config_read['display']['default']['display_options']['query']; - - // Setting the updated query option in config sync. - $summary_contents_view = \Drupal::configFactory() - ->getEditable('views.view.summary_contents_filters'); - $summary_contents_view->set('display.default.display_options.query', $query)->save(); -} - -/** - * Create new Linkit profile to view content information. - */ -function tide_site_update_8023() { - $configs = [ - 'linkit.linkit_profile.site_content' => 'linkit_profile', - ]; - module_load_include('inc', 'tide_core', 'includes/helpers'); - $config_location = [__DIR__ . '/config/install']; - foreach ($configs as $config => $type) { - $config_read = _tide_read_config($config, $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage($type); - $id = substr($config, strrpos($config, '.') + 1); - if ($storage->load($id) == NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - } -} - -/** - * Add a new Table of contents on the Site Taxonomy. - */ -function tide_site_update_8024() { - $configs = [ - 'field.storage.taxonomy_term.field_show_table_of_contents' => 'field_storage_config', - 'field.storage.taxonomy_term.field_title_of_table_of_contents' => 'field_storage_config', - 'field.field.taxonomy_term.sites.field_show_table_of_contents' => 'field_config', - 'field.field.taxonomy_term.sites.field_title_of_table_of_contents' => 'field_config', - ]; - module_load_include('inc', 'tide_core', 'includes/helpers'); - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install']; - // Check if field already exported to config/sync. - foreach ($configs as $config => $type) { - $config_read = _tide_read_config($config, $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage($type); - $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); - if ($storage->load($id) == NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - } - - // Adding the field to display form. - $entity_form_display = Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_show_table_of_contents', [ - 'weight' => 17, - 'settings' => [ - 'display_label' => TRUE, - ], - 'third_party_settings' => [], - 'type' => 'boolean_checkbox', - 'region' => 'content', - ]); - $entity_form_display->setComponent('field_title_of_table_of_contents', [ - 'weight' => 18, - 'settings' => [ - 'size' => 60, - 'placeholder' => '', - ], - 'third_party_settings' => [], - 'type' => 'string_textfield', - 'region' => 'content', - ]); - $field_group = $entity_form_display->getThirdPartySettings('field_group'); - $field_group['group_table_of_contents'] = [ - 'children' => [ - 'field_show_table_of_contents', - 'field_title_of_table_of_contents', - ], - 'parent_name' => '', - 'label' => 'Table of contents', - 'weight' => 15, - 'format_type' => 'details', - 'region' => 'content', - 'format_settings' => [ - 'show_empty_fields' => FALSE, - 'required_fields' => TRUE, - 'id' => '', - 'classes' => '', - 'description' => '', - 'open' => FALSE, - ], - ]; - $entity_form_display->setThirdPartySetting('field_group', 'group_table_of_contents', $field_group['group_table_of_contents']); - } - $entity_form_display->save(); - - // Adding the field to display view. - $entity_view_display = Drupal::entityTypeManager() - ->getStorage('entity_view_display') - ->load('taxonomy_term.sites.default'); - if ($entity_view_display) { - $entity_view_display->setComponent('field_show_table_of_contents', [ - 'weight' => 14, - 'label' => 'above', - 'settings' => [ - 'format' => 'default', - 'format_custom_false' => '', - 'format_custom_true' => '', - ], - 'third_party_settings' => [], - 'region' => 'content', - 'type' => 'boolean', - ]); - $entity_view_display->setComponent('field_title_of_table_of_contents', [ - 'weight' => 15, - 'label' => 'above', - 'settings' => [ - 'link_to_entity' => FALSE, - ], - 'third_party_settings' => [], - 'region' => 'content', - 'type' => 'string', - ]); - } - $entity_view_display->save(); - - $config_factory = \Drupal::configFactory(); - $config = $config_factory->getEditable('jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites'); - - $content = $config->get('resourceFields'); - if (!isset($content['field_show_table_of_contents'])) { - $content['field_show_table_of_contents'] = [ - 'fieldName' => 'field_show_table_of_contents', - 'publicName' => 'field_show_table_of_contents', - 'enhancer' => [ - 'id' => '', - ], - 'disabled' => FALSE, - ]; - $config->set('resourceFields', $content); - } - if (!isset($content['field_title_of_table_of_contents'])) { - $content['field_title_of_table_of_contents'] = [ - 'fieldName' => 'field_title_of_table_of_contents', - 'publicName' => 'field_title_of_table_of_contents', - 'enhancer' => [ - 'id' => '', - ], - 'disabled' => FALSE, - ]; - $config->set('resourceFields', $content); - } - $config->save(); -} - -/** - * Update linkit.linkit_profile.site_content config. - */ -function tide_site_update_8025() { - $configs = [ - 'linkit.linkit_profile.site_content' => 'linkit_profile', - ]; - \Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers'); - $config_location = [__DIR__ . '/config/install']; - foreach ($configs as $config => $type) { - $storage = \Drupal::entityTypeManager()->getStorage($type); - $id = substr($config, strrpos($config, '.') + 1); - $config_entity = $storage->load($id); - if ($config_entity !== NULL) { - $storage->delete([$config_entity]); - } - $config_read = _tide_read_config($config, $config_location, FALSE); - $new_config_entity = $storage->createFromStorageRecord($config_read); - $new_config_entity->save(); - } -} - -/** - * New field print-friendly logo. - */ -function tide_site_update_8026() { - $configs = [ - 'field.storage.taxonomy_term.field_print_friendly_logo' => 'field_storage_config', - 'field.field.taxonomy_term.sites.field_print_friendly_logo' => 'field_config', - ]; - module_load_include('inc', 'tide_core', 'includes/helpers'); - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_site') . '/config/install']; - // Check if field already exported to config/sync. - foreach ($configs as $config => $type) { - $config_read = _tide_read_config($config, $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage($type); - $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); - if ($storage->load($id) == NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - } - - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */ - $entity_form_display = \Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_print_friendly_logo', [ - 'type' => 'file_generic', - 'weight' => 3, - 'region' => 'content', - 'settings' => [ - 'progress_indicator' => 'throbber', - ], - 'third_party_settings' => [], - ]); - } - $entity_form_display->save(); - - // Adding the field to display view. - $entity_view_display = Drupal::entityTypeManager() - ->getStorage('entity_view_display') - ->load('taxonomy_term.sites.default'); - if ($entity_view_display) { - $entity_view_display->setComponent('field_print_friendly_logo', [ - 'type' => 'file_default', - 'weight' => 2, - 'label' => 'above', - 'region' => 'content', - 'settings' => [ - 'use_description_as_link_text' => TRUE, - ], - 'third_party_settings' => [], - ])->save(); - } - - $config_factory = \Drupal::configFactory(); - $config = $config_factory->getEditable('jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites'); - - $content = $config->get('resourceFields'); - if (!isset($content['field_print_friendly_logo'])) { - $content['field_print_friendly_logo'] = [ - 'fieldName' => 'field_print_friendly_logo', - 'publicName' => 'field_print_friendly_logo', - 'enhancer' => [ - 'id' => '', - ], - 'disabled' => FALSE, - ]; - $config->set('resourceFields', $content); - } -} diff --git a/tide_site.module b/tide_site.module index 39ed6a40..3e0c69df 100644 --- a/tide_site.module +++ b/tide_site.module @@ -127,11 +127,11 @@ function tide_site_entity_presave(EntityInterface $entity) { } /** - * Implements hook_field_widget_form_alter(). + * Implements hook_field_widget_single_element_form_alter(). * * @todo Extract into a service. */ -function tide_site_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) { +function tide_site_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) { $field_definition = $context['items']->getFieldDefinition(); // Restrict options to 2 levels of depth for Site field. @@ -658,6 +658,7 @@ function tide_site_taxonomy_term_delete($term) { $path_storage = \Drupal::entityTypeManager()->getStorage('path_alias'); $site_prefix = $helper->getSitePathPrefix($term); $path_ids = \Drupal::entityQuery('path_alias') + ->accessCheck(TRUE) ->condition('alias', $site_prefix . '/', 'CONTAINS') ->condition('path', '/taxonomy/term/' . $term->id(), '=') ->execute(); @@ -690,6 +691,7 @@ function tide_site_node_update($node) { foreach ($unassigned_sites as $unassigned_site_id) { $site_prefix = $helper->getSitePathPrefix($unassigned_site_id); $path_ids = \Drupal::entityQuery('path_alias') + ->accessCheck(TRUE) ->condition('alias', $site_prefix . '/', 'CONTAINS') ->condition('path', '/node/' . $node->id(), '=') ->execute();