commands-1.x-dev/commands.module

commands.module
<?php

/**
 * @file
 * Primary module hooks for DevShop Commands module.
 */

use Drupal\Core\Render\Element;
use Drupal\task\Entity\Task;
use Drupal\user\UserInterface;

/**
 * Implements hook_theme().
 */
function command_theme() {
  return [
    'command' => [
      'render element' => 'elements',
    ],
  ];
}

/**
 * Prepares variables for command templates.
 *
 * Default template: command.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing the command information and any
 *     fields attached to the entity.
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_command(array &$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
}

/**
 * Implements hook_user_cancel().
 */
function command_user_cancel($edit, UserInterface $account, $method) {
  switch ($method) {
    case 'user_cancel_reassign':
      // Anonymize commands.
      $storage = \Drupal::entityTypeManager()->getStorage('command');
      $command_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->execute();
      foreach ($storage->loadMultiple($command_ids) as $command) {
        $command->setOwnerId(0);
        $command->save();
      }
      break;
  }
}

/**
 * Describe the bundles for entity types.
 *
 * @return array
 *   An associative array of all entity bundles, keyed by the entity
 *   type name, and then the bundle name, with the following keys:
 *   - label: The human-readable name of the bundle.
 *   - uri_callback: (optional) The same as the 'uri_callback' key defined for
 *     the entity type in the EntityTypeManager, but for the bundle only. When
 *     determining the URI of an entity, if a 'uri_callback' is defined for both
 *     the entity type and the bundle, the one for the bundle is used.
 *   - translatable: (optional) A boolean value specifying whether this bundle
 *     has translation support enabled. Defaults to FALSE.
 *   - class: (optional) The fully qualified class name for this bundle. If
 *     omitted, the class from the entity type definition will be used. Multiple
 *     bundles must not use the same subclass. If a class is reused by multiple
 *     bundles, an \Drupal\Core\Entity\Exception\AmbiguousBundleClassException
 *     will be thrown.
 *
 * @see \Drupal\Core\Entity\EntityTypeBundleInfo::getBundleInfo()
 * @see hook_entity_bundle_info_alter()
 */
function command_entity_bundle_info() {
//  $bundles['command']['drush'] = [
//    'label' => t('Drush Command'),
//    'class' => \Drupal\task\Entity\Bundle\DrushTask::class
//  ];
//  return $bundles;
}

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

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