media_mpx-8.x-1.x-dev/media_mpx.module

media_mpx.module
<?php

/**
 * @file
 * Module hooks for the media_mpx module.
 */

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\media\MediaInterface;
use Drupal\media_mpx\FormAlter\MediaFormAlter;
use Drupal\media_mpx\Plugin\QueueWorker\ThumbnailDownloader;

/**
 * Implements hook_help().
 */
function media_mpx_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'media_mpx.settings':
      return [
        '#prefix' => '<p>',
        '#markup' => t('Setting up mpx for the first time? Make sure you have an mpx username and password. With that username and password, <a href="@create-user">create a user</a>, and then <a href="@create-account">create one or more accounts</a> to import content from.', [
          '@create-user' => Url::fromRoute('entity.media_mpx_user.add_form')->toString(),
          '@create-account' => Url::fromRoute('entity.media_mpx_account.add_form')->toString(),
        ]),
        '#suffix' => '</p>',
      ];
  }

  return NULL;
}

/**
 * Implements hook_theme().
 */
function media_mpx_theme() {
  return [
    'media_mpx_iframe_wrapper' => [
      'variables' => [
        'attributes' => [],
        'meta' => [],
        'content' => [],
        'entity' => NULL,
        'mpx_media' => NULL,
      ],
    ],
    'media_mpx_iframe' => [
      'variables' => [
        'url' => '',
        'attributes' => [],
      ],
    ],
  ];
}

/**
 * Implements hook_queue_info_alter().
 */
function media_mpx_queue_info_alter(&$queues) {
  // Alter the queue so we can support recreating jobs if the thumbnail fails
  // to download.
  $queues['media_entity_thumbnail']['class'] = ThumbnailDownloader::class;
}

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function media_mpx_media_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($entity instanceof MediaInterface && $operation == 'view') {
    /** @var \Drupal\media_mpx\Access\MediaAvailableAccess $access */
    $access = \Drupal::service('media_mpx.media_available_access');
    return $access->view($entity, $account);
  }

  return AccessResult::neutral();
}

/**
 * Implements hook_migration_plugins_alter().
 */
function media_mpx_migration_plugins_alter(array &$migrations) {
  // Add mappings for fields stored at mpx_video table.
  foreach ($migrations as $migration_id => $migration) {
    if ($migration['source']['plugin'] == 'media_mpx_entity_item') {
      $migrations[$migration_id]['process']['name'] = [
        'plugin' => 'get',
        'source' => 'title',
      ];
      $migrations[$migration_id]['process']['field_mpx_released_file_pids'] = [
        'plugin' => 'get',
        'source' => 'released_file_pids',
      ];
      $migrations[$migration_id]['process']['field_mpx_main_released_file_pid'] = [
        'plugin' => 'get',
        'source' => 'default_released_file_pid',
      ];
      $migrations[$migration_id]['process']['field_mpx_media_categories'] = [
        'plugin' => 'get',
        'source' => 'categories',
      ];
      $migrations[$migration_id]['process']['field_mpx_title'] = [
        'plugin' => 'get',
        'source' => 'title',
      ];
      $migrations[$migration_id]['process']['field_mpx_id'] = [
        'plugin' => 'get',
        'source' => 'id',
      ];
      $migrations[$migration_id]['process']['field_mpx_guid'] = [
        'plugin' => 'get',
        'source' => 'guid',
      ];
      $migrations[$migration_id]['process']['field_mpx_description'] = [
        'plugin' => 'get',
        'source' => 'description',
      ];
      $migrations[$migration_id]['process']['field_mpx_author'] = [
        'plugin' => 'get',
        'source' => 'author',
      ];
      $migrations[$migration_id]['process']['field_mpx_airdate'] = [
        'plugin' => 'get',
        'source' => 'airdate',
      ];
      $migrations[$migration_id]['process']['field_mpx_available_date'] = [
        'plugin' => 'get',
        'source' => 'available_date',
      ];
      $migrations[$migration_id]['process']['field_mpx_expiration_date'] = [
        'plugin' => 'get',
        'source' => 'expiration_date',
      ];
      $migrations[$migration_id]['process']['field_mpx_keywords'] = [
        'plugin' => 'get',
        'source' => 'keywords',
      ];
      $migrations[$migration_id]['process']['field_mpx_copyright'] = [
        'plugin' => 'get',
        'source' => 'copyright',
      ];
      $migrations[$migration_id]['process']['field_mpx_related_link'] = [
        'plugin' => 'get',
        'source' => 'related_link',
      ];
      $migrations[$migration_id]['process']['field_mpx_fab_rating'] = [
        'plugin' => 'get',
        'source' => 'fab_rating',
      ];
      $migrations[$migration_id]['process']['field_mpx_fab_subratings'] = [
        'plugin' => 'get',
        'source' => 'fab_sub_ratings',
      ];
      $migrations[$migration_id]['process']['field_mpx_mpaa_rating'] = [
        'plugin' => 'get',
        'source' => 'mpaa_rating',
      ];
      $migrations[$migration_id]['process']['field_mpx_mpaa_subratings'] = [
        'plugin' => 'get',
        'source' => 'mpaa_sub_ratings',
      ];
      $migrations[$migration_id]['process']['field_mpx_vchip_rating'] = [
        'plugin' => 'get',
        'source' => 'vchip_rating',
      ];
      $migrations[$migration_id]['process']['field_mpx_vchip_subratings'] = [
        'plugin' => 'get',
        'source' => 'vchip_sub_ratings',
      ];
      $migrations[$migration_id]['process']['field_mpx_exclude_countries'] = [
        'plugin' => 'get',
        'source' => 'exclude_countries',
      ];
      $migrations[$migration_id]['process']['field_mpx_countries'] = [
        'plugin' => 'get',
        'source' => 'countries',
      ];
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function media_mpx_form_media_form_alter(&$form, $form_state, $form_id) {
  $update_service = \Drupal::service('media_mpx.service.update_video_item');
  $logger = \Drupal::service('media_mpx.exception_logger');

  $media_form_alter = new MediaFormAlter($update_service, $logger);
  $media_form_alter->alter($form, $form_state, $form_id);
}

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

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