degov-8.x-2.0/modules/degov_media_video_upload/modules/degov_paragraph_video_subtitle/degov_paragraph_video_subtitle.module

modules/degov_media_video_upload/modules/degov_paragraph_video_subtitle/degov_paragraph_video_subtitle.module
<?php

use Drupal\degov_common\Common;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Implements hook_preprocess().
 */
function degov_paragraph_video_subtitle_preprocess(&$variables, $hook, &$info) {
  // Add template suggestions and libraries implemented in this module.
  Common::addThemeSuggestions($variables, $hook, $info, [
    'module_name' => 'degov_paragraph_video_subtitle',
    'entity_type' => 'paragraph',
    'entity_bundles' => ['video_subtitle'],
    'entity_view_modes' => ['preview'],
  ]);
}

/**
 * Implements hook_preprocess_HOOK().
 */
function degov_paragraph_video_subtitle_preprocess_paragraph__video_subtitle(&$variables) {
  /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
  $paragraph = $variables['paragraph'];

  $attributes = [];

  $label = $paragraph->field_subtitle_label->value;
  if (!empty($label)) {
    $attributes['label'] = $label;
  }

  $kind = $paragraph->field_subtitle_kind->value;
  if (!empty($kind)) {
    $attributes['kind'] = $kind;
  }

  $lang = $paragraph->field_subtitle_lang->value;
  if (!empty($lang)) {
    $attributes['srclang'] = $lang;
  }

  /** @var \Drupal\file\Entity\File $file */
  $file = $paragraph->field_subtitle_file->entity;
  if (!empty($file)) {
    $attributes['src'] = file_create_url($file->getFileUri());
  }

  $default = $paragraph->field_subtitle_default->value;
  if (!empty($default)) {
    $attributes['default'] = 'default';
  }

  $variables['attributes'] = $attributes;
}

/**
 * Gets the allowed values for the field_subtitle_lang field.
 *
 * @param \Drupal\field\Entity\FieldStorageConfig $definition
 *   The field definition.
 *
 * @param \Drupal\Core\Entity\ContentEntityInterface|NULL $entity
 *   The entity being created or updated.
 *
 * @param $cacheable
 *   Whether or not the results are cacheable.
 *
 * @return array
 *   An array of allowed values.
 */
function getLanguageList(FieldStorageConfig $definition, ContentEntityInterface $entity = NULL, $cacheable) {
  $options = [];
  $languages = \Drupal::languageManager()->getLanguages();

  foreach ($languages as $language) {
    $options[$language->getId()] = $language->getName();
  }

  return $options;
}

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

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