acquia_cms_page-1.3.0/acquia_cms_page.install

acquia_cms_page.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the acquia_cms_page module.
 */

use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade;
use Drupal\user\RoleInterface;

/**
 * Implements hook_install().
 */
function acquia_cms_page_install($is_syncing) {
  if (!$is_syncing) {
    // Set default node revision delete configuration for Page content type.
    $module_handler = \Drupal::service('module_handler');
    if ($module_handler->moduleExists('node_revision_delete')) {
      $config_handler = \Drupal::classResolver(ConfigHandlerFacade::class);
      $config_handler->setModuleName('node_revision_delete');
      // Node revision third party settings for page content type.
      $third_party_settings = [
        'amount' => [
          'status' => TRUE,
          'settings' => [
            'amount' => 30,
          ],
        ],
        'created' => [
          'status' => FALSE,
          'settings' => [
            'age' => 0,
          ],
        ],
        'drafts' => [
          'status' => FALSE,
          'settings' => [
            'age' => 0,
          ],
        ],
        'drafts_only' => [
          'status' => FALSE,
          'settings' => [
            'age' => 0,
          ],
        ],
      ];
      // Set default node revision delete configuration for Page content type
      // and entity node_type.
      $config_handler->processThirdPartySettings([
        'entity_type' => 'node_type',
        'bundle' => 'page',
      ], $third_party_settings);
    }
  }
}

/**
 * Implements hook_content_model_role_presave_alter().
 */
function acquia_cms_page_content_model_role_presave_alter(RoleInterface &$role) {
  switch ($role->id()) {
    case 'content_author':
      foreach ([
        'create page content',
        'edit own page content',
        'delete own page content',
      ] as $permission) {
        $role->grantPermission($permission);
      }
      break;

    case 'content_editor':
      foreach (['edit any page content', 'delete any page content'] as $permission) {
        $role->grantPermission($permission);
      }
      break;
  }
}

/**
 * Implements hook_module_preinstall().
 */
function acquia_cms_page_module_preinstall($module) {
  \Drupal::service('acquia_cms_common.utility')->setModulePreinstallTriggered($module);
}

/**
 * Implements hook_update_N().
 *
 * Update node type conditions from node_type to entity_bundle.
 */
function acquia_cms_page_update_8001() {
  // Load all pattern configuration entities.
  $pattern_config = \Drupal::configFactory()->getEditable('pathauto.pattern.page');

  // Loop patterns and swap the node_type plugin by the entity_bundle:node
  // plugin.
  if ($pattern_config->get('type') === 'canonical_entities:node') {
    $selection_criteria = $pattern_config->get('selection_criteria');
    foreach ($selection_criteria as $uuid => $condition) {
      if ($condition['id'] === 'node_type') {
        $pattern_config->set("selection_criteria.$uuid.id", 'entity_bundle:node');
        $pattern_config->save();
        break;
      }
    }
  }
}

/**
 * Remove Page:Node Revision Delete settings if site studio is not installed.
 */
function acquia_cms_page_update_8002() {
  // Stale hook_update_n() cause of changes of schema in
  // 2.x version of node_revision_delete.
}

/**
 * Implements hook_update_N().
 *
 * Update Page display modes.
 */
function acquia_cms_page_update_8003() {
  // Load and update default view mode.
  $page_image_field = [
    'field_page_image' => [
      'type' => 'entity_reference_entity_view',
      'label' => 'hidden',
      'settings' => [
        'view_mode' => 'full',
        'link' => 'false',
      ],
      'third_party_settings' => [],
      'weight' => 2,
      'region' => 'content',
    ],
  ];
  $display_modes = [
    'default',
    'card',
    'horizontal_card',
    'search_results',
    'teaser',
  ];
  $view_modes = [
    'full',
    'card',
    'large_super_landscape',
    'small',
    'teaser',
  ];
  foreach ($display_modes as $key => $display_mode) {
    $page_view_mode = \Drupal::configFactory()->getEditable('core.entity_view_display.node.page.' . $display_mode);
    if ($page_view_mode->get('hidden.field_page_image')) {
      $page_image_field['field_page_image']['settings']['view_mode'] = $view_modes[$key];
      $page_view_mode->set('content', array_merge($page_view_mode->get('content'), $page_image_field));
      if ($page_view_mode->get('content.body')) {
        $page_view_mode->set('content.body.weight', $page_view_mode->get('content.body.weight') + 1);
      }
      $page_view_mode->clear('hidden.field_page_image');
      $page_view_mode->save();
    }
  }

}

/**
 * Updates for scheduler option in Page content type.
 *
 * Implements hook_update_N().
 */
function acquia_cms_page_update_8004() {
  $formStorage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
  $formDisplay = $formStorage->load('node.page.default');
  if ($formDisplay) {
    $formDisplay
      ->setComponent('publish_on', [
        'type' => 'datetime_timestamp_no_default',
        'region' => 'content',
        'weight' => 14,
        'settings' => [],
      ])
      ->setComponent('publish_state', [
        'type' => 'scheduler_moderation',
        'region' => 'content',
        'weight' => 16,
        'settings' => [],
      ])
      ->setComponent('scheduler_settings', [
        'region' => 'content',
        'weight' => 13,
        'settings' => [],
      ])
      ->setComponent('unpublish_on', [
        'type' => 'datetime_timestamp_no_default',
        'region' => 'content',
        'weight' => 15,
        'settings' => [],
      ])
      ->setComponent('unpublish_state', [
        'type' => 'scheduler_moderation',
        'region' => 'content',
        'weight' => 17,
        'settings' => [],
      ])
      ->save();
  }
}

/**
 * Added enforced dependency in site studio templates for Acquia CMS Page.
 *
 * Implements hook_update_N().
 */
function acquia_cms_page_update_8005() {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler->moduleExists('acquia_cms_site_studio')) {
    $module_path = \Drupal::service('extension.list.module')->getPath('acquia_cms_page');
    $directory = $module_path . '/config/pack_acquia_cms_page';
    if (is_dir($directory)) {
      $files = \Drupal::service('file_system')->scanDirectory($directory, '/.*\.yml$/');
      foreach ($files as $file) {
        $sitestudio_template = \Drupal::configFactory()->getEditable($file->name);
        if ($sitestudio_template && is_null($sitestudio_template->get('dependencies.enforced.module')) && $sitestudio_template->get('status')) {
          $sitestudio_template->set('dependencies.enforced.module', [
            'acquia_cms_page',
            'acquia_cms_site_studio',
          ]);
          $sitestudio_template->save(TRUE);
        }
      }
    }
  }
}

/**
 * Deletes the Site Studio configurations containing invalid data.
 *
 * Implements hook_update_N().
 */
function acquia_cms_page_update_8006() {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler->moduleExists('acquia_cms_site_studio')) {
    $module_path = \Drupal::service('extension.list.module')->getPath('acquia_cms_page');
    $directories = [
      $module_path . '/config/pack_acquia_cms_page',
    ];
    foreach ($directories as $directory) {
      if (is_dir($directory)) {
        $files = \Drupal::service('file_system')->scanDirectory($directory, '/.*\.yml$/');
        foreach ($files as $file) {
          $sitestudio_template = \Drupal::configFactory()->getEditable($file->name);
          if ($sitestudio_template && !$sitestudio_template->isNew() && !$sitestudio_template->get("uuid") && !$sitestudio_template->get("id")) {
            $sitestudio_template->delete();
            \Drupal::logger("acquia_cms_page")->notice(
              sprintf("The configuration `%s` deleted containing invalid data.", $file->name)
            );
          }
        }
      }
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc