sector_media_gallery-8.x-2.x-dev/sector_media_gallery.install

sector_media_gallery.install
<?php

/**
 * @file
 */

use Drupal\views\Entity\View;

/**
 * Implements hook_install().
 */
function sector_media_gallery_install() {
  _sector_media_gallery_setup_permissions();
  _sector_media_gallery_setup_xml_sitemap();
}

/**
 * Helper function.
 *
 * Set up the permissions for the media_gallery content type.
 */
function _sector_media_gallery_setup_permissions() {
  $roles = [
    'content_administrator',
    'content_editor',
  ];
  foreach ($roles as $role) {
    user_role_grant_permissions(
      $role,
      [
        'create media_gallery content',
        'delete any media_gallery content',
        'delete own media_gallery content',
        'edit any media_gallery content',
        'edit own media_gallery content',
        'revert media_gallery revisions',
        'view media_gallery revisions',
      ]
    );
  }
}

/**
 * Helper function.
 *
 * Set up the sitemap settings on install.
 */
function _sector_media_gallery_setup_xml_sitemap() {
  // Check Xmlsitemap module is enabled.
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler->moduleExists('xmlsitemap')) {
    // Default data array for media_gallerys.
    $data = [
      'status' => TRUE,
      'priority' => 0.5,
      'changefreq' => 86400,
    ];
    // Load the config and save our default data.
    \Drupal::configFactory()->getEditable("xmlsitemap.settings.node.media_gallery")->setData($data)->save();
  }
}

/**
 * Implement hook_update_N
 * Add validation check for items attached to unpublished galleries.
 */
function sector_media_gallery_update_8201(&$sandbox) {
  // Load sector media gallery database.
  $view = View::load('sector_media_gallery_single_item');
  if (!$view) {
    return;
  }
  // Get database.
  $display = &$view->getDisplay('page_1');
  // Check if the specify_validatin is turn on or not.
  if ($display['display_options']['arguments']['nid']['specify_validation']) {
    return;
  }
  // Create array to overriding database.
  $validationOptions = [
    'specify_validation' => TRUE,
    'validate' => [
      'type' => "entity:node",
      'fail' => "access denied",
    ],
    'validate_options' => [
      'access' => TRUE,
      'operation' => "view",
      'multiple' => 0,
      'bundles' => [],
    ],
  ];
  // Merge the array with database.
  $display['display_options']['arguments']['nid'] = array_merge($display['display_options']['arguments']['nid'], $validationOptions);
  // Save the database.
  $view->save();
}

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

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