certificate-4.0.0-alpha1/certificate.module

certificate.module
<?php

use Drupal\Core\Link;
use Drupal\certificate\Form\CertificateConfigForm;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Implements hook_user_cancel().
 *
 * Delete the user's certificate snapshots.
 */
function certificate_user_delete($account) {
  $csids = \Drupal::entityQuery('certificate_snapshot')
    ->condition('uid', $account->id())
    ->execute();
  foreach ($csids as $csid) {
    \Drupal::entityTypeManager()->getStorage('certificate_snapshot')->load($csid)->delete();
  }
}

/**
 * Get mapper options
 */
function certificate_get_certificate_mappers(BaseFieldDefinition $definition = NULL, ContentEntityInterface $entity = NULL) {
  $options = [];
  $certificate_mappers = Drupal::service('plugin.manager.certificate_mapper');
  $mapper_definitions = $certificate_mappers->getDefinitions();

  foreach ($mapper_definitions as $map_type => $map) {
    $plugin = $certificate_mappers->createInstance($map_type, ['of' => 'configuration values']);
    $options[$map_type] = $map['label'];
  }

  return $options;
}

/**
 * Get mapper value options
 */
function certificate_get_certificate_mapper_values(BaseFieldDefinition $definition = NULL, ContentEntityInterface $entity = NULL) {
  $options = [];
  $certificate_mappers = Drupal::service('plugin.manager.certificate_mapper');
  $mapper_definitions = $certificate_mappers->getDefinitions();

  foreach ($mapper_definitions as $map_type => $map) {
    $plugin = $certificate_mappers->createInstance($map_type, ['of' => 'configuration values']);
    $options += $plugin->getMapKeys();
  }

  return $options;
}

/**
 *  Helper to return a list of certificate templates suitable as options in a select list
 *
 * @return array
 */
function certificate_get_certificate_options() {
  return CertificateConfigForm::getCertificateTemplateOptions();
}

/**
 * Returns a list of all entity types with an entity reference field targeting certificate_mapping entities
 *
 * @return array
 *   Array of entity types containing certificate mapping fields.
 */
function certificate_get_entity_types() {
  $entity_types = [];
  /* @var $fields Drupal\field\Entity\FieldConfig[] */
  $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_type' => 'entity_reference']);
  foreach ($fields as $field) {
    if ($field->getSetting('target_type') == 'certificate_mapping') {
      $entity_types[$field->getTargetEntityTypeId()] = $field->getTargetEntityTypeId();
    }
  }
  return $entity_types;
}

/**
 * Implements hook_page_attachments().
 */
function certificate_page_attachments(&$page) {
  $page['#attached']['library'][] = 'certificate/styles';
}

/**
 * Implements hook_help().
 */
function certificate_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'entity.certificate_type.collection':
      return '<p>' . t('Certificate template types are used to create certificate templates. For example instead of a single WYSIWYG field, you can create a certificate template type that uses text fields and image uploads. Then you can use view modes to configure the certificate output.') . '</p>';
    case 'entity.certificate_template.collection':
      return '<p>' . t('Certificate templates are run through token replacement with entity and user data, then converted to a PDF for a user to download.') . '</p>';
  }
}

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

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