You are here

lightning_landing_page.module in Lightning Layout 8

Same filename and directory in other branches
  1. 8.2 modules/lightning_landing_page/lightning_landing_page.module

Contains landing page functionality for Lightning.

File

modules/lightning_landing_page/lightning_landing_page.module
View source
<?php

/**
 * @file
 * Contains landing page functionality for Lightning.
 */
use Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface;
use Drupal\Core\Plugin\ObjectWithPluginCollectionInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\node\Entity\NodeType;
use Drupal\workflows\WorkflowInterface;

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function lightning_landing_page_field_config_insert(FieldConfigInterface $field) {

  // Don't do anything during config sync.
  if (\Drupal::isConfigSyncing()) {
    return;
  }
  elseif ($field
    ->id() == 'node.landing_page.field_meta_tags') {
    $component = [
      'type' => 'metatag_empty_formatter',
      'region' => 'content',
    ];
    lightning_layout_entity_get_display('node', 'landing_page')
      ->setComponent('field_meta_tags', $component)
      ->save();
    lightning_layout_entity_get_display('node', 'landing_page', 'full')
      ->setComponent('field_meta_tags', $component)
      ->save();
    lightning_layout_entity_get_display('node', 'landing_page', 'teaser')
      ->setComponent('field_meta_tags', $component)
      ->save();
    lightning_layout_entity_get_form_display('node', 'landing_page')
      ->setComponent('field_meta_tags', [
      'type' => 'metatag_firehose',
      'region' => 'content',
    ])
      ->save();
  }
}

/**
 * Implements hook_modules_installed().
 */
function lightning_landing_page_modules_installed(array $modules) {

  // Don't do anything during config sync.
  if (\Drupal::isConfigSyncing()) {
    return;
  }
  $node_type = NodeType::load('landing_page');
  if (in_array('lightning_search', $modules, TRUE)) {
    lightning_search_node_type_insert($node_type);
  }
  if (in_array('menu_ui', $modules, TRUE)) {
    $node_type
      ->setThirdPartySetting('menu_ui', 'available_menus', [
      'main',
    ])
      ->setThirdPartySetting('menu_ui', 'parent', 'main:')
      ->save();
  }
}

/**
 * Implements hook_ENITY_TYPE_presave().
 */
function lightning_landing_page_workflow_presave(WorkflowInterface $workflow) {
  if (Drupal::isConfigSyncing()) {
    return;
  }
  elseif ($workflow
    ->isNew() && $workflow
    ->id() === 'editorial' && Drupal::moduleHandler()
    ->moduleExists('lightning_workflow')) {
    $type_plugin = $workflow
      ->getTypePlugin();
    if ($type_plugin instanceof ContentModerationInterface) {
      $type_plugin
        ->addEntityTypeAndBundle('node', 'landing_page');

      // Since this hook is invoked _after_ Workflow::preSave(), we need to
      // ensure that the stored settings for the type plugin will be up-to-date
      // with the changes we've made here.
      if ($workflow instanceof ObjectWithPluginCollectionInterface) {
        foreach ($workflow
          ->getPluginCollections() as $key => $plugin_collection) {
          $workflow
            ->set($key, $plugin_collection
            ->getConfiguration());
        }
      }
    }
  }
}