You are here

deploy.module in Deploy - Content Staging 8

Same filename and directory in other branches
  1. 5 deploy.module
  2. 6 deploy.module
  3. 7.3 deploy.module
  4. 7.2 deploy.module

UI module to deploy content entities.

File

deploy.module
View source
<?php

/**
 * @file
 * UI module to deploy content entities.
 */
use Drupal\Core\Url;

/**
 * Implements hook_toolbar().
 */
function deploy_toolbar() {
  $user = \Drupal::currentUser();
  $items['deploy'] = [
    '#type' => 'toolbar_item',
    'tab' => [
      '#type' => 'link',
      '#title' => t('Deploy'),
      '#url' => Url::fromRoute('entity.replication.add_form'),
      '#access' => \Drupal::entityTypeManager()
        ->getAccessControlHandler('replication')
        ->createAccess('', $user),
      '#attributes' => [
        'title' => t('Deploy'),
        'class' => [
          'toolbar-icon',
          'toolbar-icon-deploy',
          'use-ajax',
        ],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => json_encode([
          'width' => '50%',
        ]),
      ],
    ],
    '#wrapper_attributes' => [
      'class' => [
        'deploy-toolbar-tab',
      ],
    ],
    '#attached' => [
      'library' => [
        'deploy/drupal.deploy.toolbar',
      ],
    ],
  ];
  return $items;
}

/**
 * Implements hook_toolbar_alter().
 */
function deploy_toolbar_alter(&$items) {
  $items['workspace_switcher']['tray']['deployments'] = [
    '#type' => 'link',
    '#title' => t('Deployments'),
    '#url' => Url::fromRoute('entity.replication.collection'),
    '#attributes' => [
      'class' => 'deployments',
      'title' => 'View all deployments',
    ],
  ];
}

/**
 * Implements hook_entity_type_alter().
 */
function deploy_entity_type_alter(array &$entity_types) {
  if (!empty($entity_types['replication'])) {

    /** @var \Drupal\Core\Entity\EntityTypeInterface $replication */
    $replication = $entity_types['replication'];
    $replication
      ->setHandlerClass('list_builder', 'Drupal\\deploy\\ReplicationListBuilder');
    $replication
      ->setHandlerClass('access', 'Drupal\\deploy\\ReplicationAccessControlHandler');
    $replication
      ->setHandlerClass('route_provider', [
      'html' => 'Drupal\\Core\\Entity\\Routing\\AdminHtmlRouteProvider',
    ]);
    $replication
      ->setHandlerClass('form', [
      'default' => 'Drupal\\deploy\\Entity\\Form\\ReplicationForm',
      'add' => 'Drupal\\deploy\\Entity\\Form\\ReplicationForm',
      'delete' => 'Drupal\\deploy\\Entity\\Form\\ReplicationDeleteForm',
    ]);
    $replication
      ->setLinkTemplate('collection', '/admin/structure/deployment');
    $replication
      ->setLinkTemplate('delete-form', '/admin/structure/deployment/{replication}/delete');
    $replication
      ->set('field_ui_base_route', 'entity.replication.collection');
    $replication
      ->set('admin_permission', 'administer workspaces');
  }
}