You are here

entity_print.install in Entity Print 8

Same filename and directory in other branches
  1. 8.2 entity_print.install
  2. 7 entity_print.install

Entity Print installation file.

File

entity_print.install
View source
<?php

/**
 * @file
 * Entity Print installation file.
 */

/**
 * Implements hook_install().
 */
function entity_print_install() {
  $entity_type_manager = \Drupal::entityTypeManager();
  $storage = $entity_type_manager
    ->getStorage('entity_view_mode');

  // Add a PDF view mode if the node entity type exists and the PDF view mode
  // does not already exist.
  if ($entity_type_manager
    ->getDefinition('node', FALSE) && !$storage
    ->load('node.pdf')) {
    $storage
      ->create(array(
      'targetEntityType' => 'node',
      'id' => 'node.pdf',
      'status' => TRUE,
      'label' => t('PDF'),
    ))
      ->save();
  }
}

/**
 * Implements hook_requirements().
 */
function entity_print_requirements($phase) {
  $requirements = [];
  if ($phase !== 'runtime') {
    return $requirements;
  }
  $definitions = \Drupal::service('plugin.manager.entity_print.pdf_engine')
    ->getDefinitions();
  $has_one_engine = FALSE;
  foreach ($definitions as $definition) {

    /** @var \Drupal\entity_print\Plugin\PdfEngineInterface $class */
    $class = $definition['class'];
    if ($class::dependenciesAvailable()) {
      $has_one_engine = TRUE;
    }
  }
  if (!$has_one_engine) {
    $requirements['entity_print_pdf_engine_available'] = [
      'title' => t('PDF Engine available'),
      'description' => t('At least one valid PDF engine must be available to use Entity Print. See the <a href=":docs">documentation</a>', [
        ':docs' => 'https://www.drupal.org/node/2706755',
      ]),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  return $requirements;
}

/**
 * Upgrade the permissions inline with the more granular permissions.
 */
function entity_print_update_8101() {
  $roles = user_roles();
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('entity print access')) {
      $role
        ->grantPermission('bypass entity print access');
      $role
        ->revokePermission('entity print access');
      $role
        ->save();
    }
  }
}

Functions

Namesort descending Description
entity_print_install Implements hook_install().
entity_print_requirements Implements hook_requirements().
entity_print_update_8101 Upgrade the permissions inline with the more granular permissions.