varbase_media-9.0.0-alpha1/varbase_media.module

varbase_media.module
<?php

/**
 * @file
 * Contains varbase_media.module.
 */

use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\entity_browser_generic_embed\OverrideHelper;
use Drupal\varbase_media\Plugin\media\Source\VarbaseMediaRemoteVideo;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Url;
use Drupal\media\OEmbed\Provider;
use Drupal\field\Entity\FieldConfig;
use Drupal\image\Plugin\Field\FieldType\ImageItem;

// Include all helpers.
include_once __DIR__ . '/includes/helpers.inc';

// Include Varbase Media global tokens.
include_once __DIR__ . '/varbase_media.tokens.inc';

/**
 * Implements hook_preprocess_field().
 */
function varbase_media_preprocess_field(&$variables) {

  if ($variables['element']['#formatter'] == 'varbase_oembed') {

    // Provide an extra variable to the field template when the field uses
    // a formatter of type 'varbase_oembed'.
    $iframe_url_helper = \Drupal::service('media.oembed.iframe_url_helper');

    $entity = $variables['element']['#object'];

    $view_mode = $variables['element']['#view_mode'];
    $field_name = $variables['element']['#field_name'];
    $bundle = $variables['element']['#bundle'];

    // Get the field formatter settings...
    $entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
    $field_display = $entity_display->getComponent($field_name);

    if ($bundle == "remote_video") {
      $max_width = $field_display['settings']['max_width'];
      $max_height = $field_display['settings']['max_height'];
      $item = $variables['element']["#items"]->first();

      $main_property = $item->getFieldDefinition()->getFieldStorageDefinition()->getMainPropertyName();
      $value = $item->{$main_property};
      $provider = $entity->field_provider->value;
      $url = Url::fromRoute('media.oembed_iframe', [], [
        'query' => [
          'url' => $value,
          'max_width' => $max_width,
          'max_height' => $max_height,
          'type' => "remote_video",
          'provider' => strtolower($provider ?? ''),
          'view_mode' => $view_mode,
          'hash' => $iframe_url_helper->getHash($value, $max_width, $max_height, $provider, $view_mode),
        ],
      ]);

      $variables['items'][0]['content']['#attributes']['src'] = $url->toString();
    }
  }
  elseif ($variables['element']['#formatter'] == 'oembed') {
    // Fallback option for oembed old way, In case of change back to oembed.
    // -------
    // Provide an extra variable to the field template when the field uses
    // a formatter of type 'oembed'.
    $resource_fetcher = \Drupal::service('media.oembed.resource_fetcher');
    $url_resolver = \Drupal::service('media.oembed.url_resolver');
    $iframe_url_helper = \Drupal::service('media.oembed.iframe_url_helper');

    $entity = $variables['element']['#object'];

    $view_mode = $variables['element']['#view_mode'];
    $field_name = $variables['element']['#field_name'];
    $bundle = $variables['element']['#bundle'];

    // Get the field formatter settings...
    $entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
    $field_display = $entity_display->getComponent($field_name);

    if ($bundle == "remote_video") {
      $max_width = $field_display['settings']['max_width'];
      $max_height = $field_display['settings']['max_height'];
      $item = $variables['element']["#items"]->first();
      $main_property = $item->getFieldDefinition()->getFieldStorageDefinition()->getMainPropertyName();
      $value = $item->{$main_property};

      // Fallback option for oembed old way, In case of change back to oembed
      // fetch resource way.
      $resource_url = $url_resolver->getResourceUrl($value, $max_width, $max_height);
      $resource = $resource_fetcher->fetchResource($resource_url);
      $provider = $resource->getProvider()->getName();
      $url = Url::fromRoute('media.oembed_iframe', [], [
        'query' => [
          'url' => $value,
          'max_width' => $max_width,
          'max_height' => $max_height,
          'type' => "remote_video",
          'provider' => strtolower($provider ?? ''),
          'view_mode' => $view_mode,
          'hash' => $iframe_url_helper->getHash($value, $max_width, $max_height, $provider, $view_mode),
        ],
      ]);

      $variables['items'][0]['content']['#attributes']['src'] = $url->toString();
    }
  }

}

/**
 * Implements hook_entity_presave().
 */
function varbase_media_entity_presave(EntityInterface $entity) {
  if ($entity->getEntityType()->id() == 'media' && $entity->bundle->target_id == 'remote_video') {
    // If the field_provider exists in the remote video media type.
    $field_field_media_remote_video_field_provider = FieldConfig::loadByName('media', 'remote_video', 'field_provider');
    if (isset($field_field_media_remote_video_field_provider)) {
      // Fetch the resource from the URL and save in the field_provider.
      $url_resolver = \Drupal::service('media.oembed.url_resolver');
      $resource_fetcher = \Drupal::service('media.oembed.resource_fetcher');
      $resource_url = $url_resolver->getResourceUrl(($entity->field_media_oembed_video->value));
      $resource = $resource_fetcher->fetchResource($resource_url);
      $provider = strtolower($resource->getProvider()->getName() ?? '');
      if ($entity->field_provider->value != $provider) {
        $entity->set('field_provider', $provider);
      }
    }
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function varbase_media_preprocess_media_oembed_iframe(&$variables) {
  // Send variables for all oembed iframe theme template.
  $query = \Drupal::request()->query;
  $variables['type'] = $query->get('type');
  $variables['provider'] = $query->get('provider');
  $variables['view_mode'] = $query->get('view_mode');
  $variables['base_path'] = base_path();
  $variables['varbase_media_path'] = \Drupal::service('module_handler')->getModule('varbase_media')->getPath();
}

/**
 * Implements hook_theme_suggestions_media_oembed_iframe_alter().
 */
function varbase_media_theme_suggestions_media_oembed_iframe_alter(&$suggestions, &$vars) {
  // Suggestions go here.
  $query = \Drupal::request()->query;
  $type = $query->get('type');
  $provider = $query->get('provider');
  $view_mode = $query->get('view_mode');
  if ($type && $provider) {
    $suggestions[] = "media_oembed_iframe__" . $provider;
    $suggestions[] = "media_oembed_iframe__" . $provider . "__" . $view_mode;
    $suggestions[] = "media_oembed_iframe__" . $view_mode;
    $suggestions[] = "media_oembed_iframe__" . $type;
    $suggestions[] = "media_oembed_iframe__" . $type . "__" . $view_mode;
    $suggestions[] = "media_oembed_iframe__" . $type . "__" . $provider;
    $suggestions[] = "media_oembed_iframe__" . $type . "__" . $provider . "__" . $view_mode;
  }
}

/**
 * Implements hook_ckeditor_css_alter().
 */
function varbase_media_ckeditor_css_alter(array &$css, Editor $editor) {

  // Varbase media path.
  $varbase_media_path = Drupal::service('module_handler')->getModule('varbase_media')->getPath();

  // Attached the varbase media common style.
  $css[] = $varbase_media_path . '/css/theme/varbase_media.common.css';

  // Attached the varbase media common logged in users style.
  $css[] = $varbase_media_path . '/css/theme/varbase_media.common_logged.css';
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function varbase_media_form_entity_embed_dialog_alter(&$form, FormStateInterface $form_state, $form_id) {
  // Only at the embed step.
  if ($form_state->get('step') == 'embed') {

    // Get the entity values and attributes.
    $entity_element = [];
    $entity_element += $form_state->get('entity_element');
    $form_state->set('entity_element', $entity_element);
    $entity = $form_state->get('entity');

    // Get the entity bundle type.
    $bundle_type = $entity->bundle();
    $builder = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());

    // Restrict the logic only to the media entity type.
    if ($entity->getEntityTypeId() == "media") {
      switch ($bundle_type) {

        case "image":
          // Image Media for review.
          $media_view_mode = $builder->view($entity, 's03');
          $media_markup = \Drupal::service('renderer')->renderRoot($media_view_mode);

          // Render the Embed entity.
          $form['entity'] = [
            '#type' => 'item',
            '#markup' => $media_markup,
          ];

          // Change the "data align" field from radio buttons to Select list.
          $form['attributes']['data-align']['#type'] = 'select';
          $form['attributes']['data-align']['#wrapper_attributes'] = '';
          $form['attributes']['data-align']['#description'] = t('Choose the positioning of the image.');
          $form['attributes']['data-align']['#weight'] = -10;

          // Add description for the caption field.
          $form['attributes']['data-caption'] += [
            '#description' => t('A caption will be displayed under the image, to describe it in context of your content.'),
          ];

          // Adding the updated alt text to the media entity.
          if (isset($entity_element['alt'])) {
            $entity->field_media_image->alt = $entity_element['alt'];
          }

          // Adding the updated title text to the media entity.
          if (isset($entity_element['title'])) {
            $entity->field_media_image->title = $entity_element['title'];
          }

          if (isset($form['attributes']['data-entity-embed-display-settings'])) {
            $form['attributes']['data-entity-embed-display-settings']['link_url']['#description'] = t('Start typing the title of a piece of content to select it. You can also enter an <br /> internal path such as /node/add or an external URL such as http://example.com.');
          }

          $entity->save();
          break;

        case "video":
        case "remote_video":
          // Video Media for review.
          $media_view_mode = $builder->view($entity, 's06');
          $media_markup = \Drupal::service('renderer')->renderRoot($media_view_mode);

          // Render the Embed entity.
          $form['entity'] = [
            '#type' => 'item',
            '#markup' => $media_markup,
          ];

          if (isset($form['attributes']['data-align'])) {
            unset($form['attributes']['data-align']);
          }

          if (isset($form['attributes']['data-entity-embed-display-settings'])) {
            unset($form['attributes']['data-entity-embed-display-settings']);
          }

          if (isset($form['attributes']['data-caption'])) {
            unset($form['attributes']['data-caption']);
          }

          if (isset($form['attributes']['data-entity-embed-display'])) {
            $form['attributes']['data-entity-embed-display']['#access'] = FALSE;
            $form['attributes']['data-entity-embed-display']['#default_value'] = 'view_mode:media.original';
          }

          break;

        case "gallery":
          // Gallery Media for review.
          $media_view_mode = $builder->view($entity, 'browser_teaser');
          $media_markup = \Drupal::service('renderer')->renderRoot($media_view_mode);

          // Render the Embed entity.
          $form['entity'] = [
            '#type' => 'item',
            '#markup' => '<div class="gallery-entity-embed-dialog-step--embed"><div class="media-library-item">' . $media_markup . '</div></div>',
          ];

          // Render the Embed entity.
          if (isset($form['attributes']['data-align'])) {
            unset($form['attributes']['data-align']);
          }

          if (isset($form['attributes']['data-entity-embed-display-settings'])) {
            unset($form['attributes']['data-entity-embed-display-settings']);
          }

          if (isset($form['attributes']['data-caption'])) {
            unset($form['attributes']['data-caption']);
          }

          if (isset($form['attributes']['data-entity-embed-display'])) {
            $form['attributes']['data-entity-embed-display']['#access'] = FALSE;
            $form['attributes']['data-entity-embed-display']['#default_value'] = 'view_mode:media.full';
          }
          break;

        default:
          if (isset($form['attributes']['data-entity-embed-display-settings'])) {
            unset($form['attributes']['data-entity-embed-display-settings']);
          }
      }
      if (Drupal::service('module_handler')->moduleExists('blazy')) {
        // Attach the Blazy library.
        $form['#attached']['library'][] = 'blazy/load';
      }

      // No revision information or revision log message.
      if (isset($form['revision_information'])) {
        $form['revision_information']['#disabled'] = TRUE;
        $form['revision_information']['#attributes']['style'][] = 'display: none;';
        $form['revision_information']['#prefix'] = '<div style="display: none;">';
        $form['revision_information']['#suffix'] = '</div>';
      }

      // Hide revision.
      if (isset($form['revision'])) {
        $form['revision']['#default_value'] = TRUE;
        $form['revision']['#disabled'] = TRUE;
        $form['revision']['#attributes']['style'][] = 'display: none;';
      }

      // Hide revision log message.
      if (isset($form['revision_log_message'])) {
        $form['revision_log_message']['#disabled'] = TRUE;
        $form['revision_log_message']['#attributes']['style'][] = 'display: none;';
      }
    }
    else {
      // Remove all media fields for other entity types like ( node, term, or user).
      if (isset($form['attributes']['data-caption'])) {
        unset($form['attributes']['data-caption']);
      }
      if (isset($form['attributes']['data-align'])) {
        unset($form['attributes']['data-align']);
      }
    }
  }
}

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function varbase_media_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {

  // No revision information or revision log message.
  if (isset($entity_form['revision_information'])) {
    $entity_form['revision_information']['#disabled'] = TRUE;
    $entity_form['revision_information']['#attributes']['style'][] = 'display:none;';
    $entity_form['revision_information']['#prefix'] = '<div style="display: none;">';
    $entity_form['revision_information']['#suffix'] = '</div>';
  }

  // Hide revision.
  if (isset($entity_form['revision'])) {
    $entity_form['revision']['#default_value'] = TRUE;
    $entity_form['revision']['#disabled'] = TRUE;
    $entity_form['revision']['#attributes']['style'][] = 'display: none;';
  }

  // Hide revision log message.
  if (isset($entity_form['revision_log_message'])) {
    $entity_form['revision_log_message']['#disabled'] = TRUE;
    $entity_form['revision_log_message']['#attributes']['style'][] = 'display: none;';
  }
}

/**
 * Implements hook_theme_registry_alter().
 */
function varbase_media_theme_registry_alter(&$theme_registry) {
  // Varbase Media path.
  if (isset($theme_registry['entity_embed_container'])) {
    $varbase_media_path = Drupal::service('module_handler')->getModule('varbase_media')->getPath();
    $theme_registry['entity_embed_container']['path'] = $varbase_media_path . '/templates';
  }

  if (isset($theme_registry['fieldset__media_library_widget'])) {
    $varbase_media_path = Drupal::service('module_handler')->getModule('varbase_media')->getPath();
    $theme_registry['fieldset__media_library_widget']['path'] = $varbase_media_path . '/templates';
  }

  if (isset($theme_registry['media_library_item'])) {
    $media_library_path = Drupal::service('module_handler')->getModule('media_library')->getPath();
    $theme_registry['media_library_item']['path'] = $media_library_path . '/templates';
  }

  if (isset($theme_registry['media_library_item__widget'])) {
    $media_library_path = Drupal::service('module_handler')->getModule('media_library')->getPath();
    $theme_registry['media_library_item__widget']['path'] = $media_library_path . '/templates';
  }

}

/**
 * Implements hook_preprocess_media_library_item__widget().
 */
function varbase_media_preprocess_media_library_item__widget(array &$variables) {
  $variables['content']['remove_button']['#attributes']['class'][] = 'media-library-item__remove';
  $variables['content']['remove_button']['#attributes']['class'][] = 'icon-link';
}

/**
 * Implements hook_preprocess_media_library_item().
 */
function varbase_media_preprocess_media_library_item(array &$variables) {
  $variables['attributes']['class'][] = 'media-library-item';
  $variables['attributes']['class'][] = 'media-library-item--grid';
}

/**
 * Implements hook_preprocess_fieldset__media_library_widget().
 */
function varbase_media_preprocess_fieldset__media_library_widget(array &$variables) {
  $variables['attributes']['class'][] = 'media-library-widget';
}

/**
 * Implements hook_preprocess_container__media_library_widget_selection().
 */
function varbase_media_preprocess_container__media_library_widget_selection(array &$variables) {
  $variables['attributes']['class'][] = 'media-library-selection';
}

/**
 * Implements hook_preprocess_HOOK().
 */
function varbase_media_preprocess_entity_embed_container(&$variables) {
  $variables['url'] = isset($variables['element']['#context']['data-entity-embed-display-settings']['link_url']) ? UrlHelper::filterBadProtocol($variables['element']['#context']['data-entity-embed-display-settings']['link_url']) : '';
}

/**
 * Implements hook_entity_view_alter().
 */
function varbase_media_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {

  if ($entity->getEntityTypeId() == 'media'
    && $build['#view_mode'] != 'field_preview') {

    // Attached the varbase media common library.
    $build['#attached']['library'][] = 'varbase_media/common';

    if (!(\Drupal::currentUser()->isAnonymous())) {
      // Attached the varbase media common logged in users library.
      $build['#attached']['library'][] = 'varbase_media/common_logged';
    }

    if (isset($build['field_media_cover_image'])
      && isset($build['field_media_cover_image']['#items'])) {

      $fields = $build['field_media_cover_image']['#items'];

      if (is_object($fields)) {

        // Hide thumbnail of media if we do have cover image data.
        if (isset($build['thumbnail'])) {
          $build['thumbnail']['#access'] = FALSE;
        }

        $build['field_media_cover_image']['#attached']['library'][] = 'varbase_media/varbase_video_player';
      }
    }

    // Attach the varbase media video library for video embed field.
    if (isset($build['field_media_oembed_video'])
      && isset($build['field_media_oembed_video'][0])) {

      $build['field_media_oembed_video'][0]['#attached']['library'][] = 'varbase_media/varbase_video_player';
    }

    // Attach the varbase media video library for video file field.
    if (isset($build['field_media_video_file'])) {
      $build['field_media_video_file']['#attached']['library'][] = 'varbase_media/varbase_video_player';
    }
  }
}

/**
 * Implements hook_media_source_info_alter().
 */
function varbase_media_media_source_info_alter(array &$sources) {

  // Remote Video.
  $sources['oembed:video']['input_match'] = [
    'constraint' => 'oembed_resource',
    'field_types' => [
      'link',
      'string',
      'string_long',
    ],
  ];
  $sources['oembed:video']['preview'] = TRUE;
  OverrideHelper::pluginClass($sources['oembed:video'], VarbaseMediaRemoteVideo::class);

}

/**
 * Implements hook_form_alter().
 */
function varbase_media_form_alter(&$form, &$form_state, $form_id) {
  if ($form_state->getFormObject() instanceof EntityFormInterface) {
    $entity_type = $form_state->getFormObject()->getEntity()->getEntityTypeId();

    // Only for media entity type.
    if ($entity_type == 'media') {
      // No revision information or revision log message.
      if (isset($form['revision_information'])) {
        $form['revision_information']['#disabled'] = TRUE;
        $form['revision_information']['#attributes']['style'][] = 'display:none;';
        $form['revision_information']['#prefix'] = '<div style="display: none;">';
        $form['revision_information']['#suffix'] = '</div>';
      }

      // Hide revision.
      if (isset($form['revision'])) {
        $form['revision']['#default_value'] = TRUE;
        $form['revision']['#disabled'] = TRUE;
        $form['revision']['#attributes']['style'][] = 'display: none;';
      }

      // Hide revision log message.
      if (isset($form['revision_log_message'])) {
        $form['revision_log_message']['#disabled'] = TRUE;
        $form['revision_log_message']['#attributes']['style'][] = 'display: none;';
      }
    }
  }

  if ($form_id == 'entity_browser_image_browser_form'
      || $form_id == 'entity_browser_media_browser_form'
      || $form_id == 'entity_browser_editor_media_browser_form') {
    $form['#attached']['library'][] = 'varbase_media/auto_fill_media_data';
  }

  if ($form_id === "entity_browser_widgets_config_form") {

    // Attach the varbase media common library.
    $form['#attached']['library'][] = 'varbase_media/common';

    if (!(\Drupal::currentUser()->isAnonymous())) {
      // Attached the varbase media common logged in users library.
      $form['#attached']['library'][] = 'varbase_media/common_logged';
    }
  }

  if ($form_id === 'editor_media_dialog') {
    if (isset($form_state->getUserInput()['editor_object'])) {
      $editor_object = $form_state->getUserInput()['editor_object'];
      $media_embed_element = $editor_object['attributes'];

      if (isset($media_embed_element['data-entity-type'])
       && $media_embed_element['data-entity-type'] == 'media') {
        $media = \Drupal::service('entity.repository')->loadEntityByUuid('media', $media_embed_element['data-entity-uuid']);

        if (isset($media)) {
          $media_type = $media->bundle();

          switch ($media_type) {
            case 'image':
              if (isset($form['alt'])) {
                $form['alt']['#required'] = TRUE;

                $field_definition = $media->getSource()->getSourceFieldDefinition($media->bundle->entity);
                $item_class = $field_definition->getItemDefinition()->getClass();
                if (is_a($item_class, ImageItem::class, TRUE)) {
                  $image_field_name = $field_definition->getName();

                  // We'll want the alt text from the same language as the host.
                  if (!empty($editor_object['hostEntityLangcode']) && $media->hasTranslation($editor_object['hostEntityLangcode'])) {
                    $media = $media->getTranslation($editor_object['hostEntityLangcode']);
                  }
                  $alt = $media_embed_element['alt'] ?? $media->{$image_field_name}->alt;
                  $form['alt']['#default_value'] = $alt;
                  $form['alt']['#placeholder'] = $media->{$image_field_name}->alt;
                }
              }
              break;

            case 'audio':
            case 'file':
              if (isset($form['view_mode'])) {
                $form['view_mode']['#access'] = FALSE;
              }
              break;

            case 'video':
            case 'remote_video':
              if (isset($form['caption'])) {
                $form['caption']['#access'] = FALSE;
                $form['caption']['#default_value'] = FALSE;
              }
              break;
          }
        }
      }
    }
  }

  if ($form_id === 'media_bulk_upload_form') {
    $form['#submit'][] = '_varbase_media_bulk_upload_form_submit_handler';
  }

}

/**
 * Varbase media bulk upload form submit handler.
 *
 * Redirect the user back to the Media page (/admin/content/media)
 * after successful bulk upload.
 */
function _varbase_media_bulk_upload_form_submit_handler(&$form, &$form_state) {
  if (\Drupal::moduleHandler()->moduleExists('media_library')) {
    $media_library_grid_url = Url::fromRoute('view.media_library.page');
    $form_state->setRedirectUrl($media_library_grid_url);
  }
  else {
    $media_library_table_url = Url::fromRoute('entity.media.collection');
    $form_state->setRedirectUrl($media_library_table_url);
  }
}

/**
 * Implements hook_theme().
 */
function varbase_media_theme($existing, $type, $theme, $path) {

  return [
    'media_oembed_iframe__remote_video' => [
      'template' => 'media-oembed-iframe--remote-video',
      'variables' => [
        'provider' => NULL,
        'media' => NULL,
      ],
    ],
    'media_entity_gallery_post' => [
      'variables' => [
        'post' => NULL,
        'shortcode' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_preprocess_HOOK().
 */
function varbase_media_preprocess_media_oembed_iframe__remote_video(&$variables) {
  // Send variables for the remote_video oembed iframe theme template.
  $query = \Drupal::request()->query;
  $variables['type'] = $query->get('type');
  $variables['provider'] = $query->get('provider');
  $variables['view_mode'] = $query->get('view_mode');
  $variables['base_path'] = base_path();
  $variables['varbase_media_path'] = \Drupal::service('module_handler')->getModule('varbase_media')->getPath();
}

/**
 * Implements hook_entity_embed_alter().
 */
function varbase_media_entity_embed_alter(array &$build, EntityInterface $entity, array &$context) {

  // Only for entity embed review inside the CKEditor.
  $preview_route_name = \Drupal::routeMatch()->getRouteName();
  if ($preview_route_name == 'embed.preview' || $preview_route_name == 'entity_embed.preview') {

    // Switch view mode for gallery in the CKEditor to show the Browser Teaser.
    if (isset($context['data-embed-button'])
        && $context['data-embed-button'] == 'gallery') {

      // Remove the contextual links.
      if (isset($build['#contextual_links'])) {
        unset($build['#contextual_links']);
      }

      if ($build['#context']['data-entity-embed-display'] == 'view_mode:media.full') {
        $build['#context']['data-entity-embed-display'] = 'view_mode:media.browser_teaser';
        $build['entity']['#view_mode'] = 'browser_teaser';
      }
    }

  }

}

/**
 * Implements hook_oembed_resource_url_alter().
 */
function varbase_media_oembed_resource_url_alter(array &$parsed_url, Provider $provider) {
  // Process arguments for vimeo videos to be included in oEmbed.
  if ($provider->getName() == 'Vimeo') {
    $url = $parsed_url['query']['url'];
    // Use '/&' as a separator between arguments.
    $url = str_replace('&', '/&', $url);
    $url = str_replace('?', '/&', $url);
    $parsed_url['query']['url'] = $url;
  }
}

/**
 * Implements hook_library_info_alter().
 */
function varbase_media_library_info_alter(&$libraries, $extension) {
  if ($extension === 'media_library' && isset($libraries['widget'])) {
    $libraries['widget']['dependencies'][] = 'varbase_media/media_library_enhancements';
  }

  if ($extension === 'ckeditor5') {
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'drimage_improved/drimage_improved';
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'varbase_media/common';
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'varbase_media/common_logged';
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'varbase_media/varbase_video_player';
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'varbase_media/ckeditor_drimage';
    $libraries['internal.drupal.ckeditor5.media']['dependencies'][] = 'varbase_media/ckeditor_varbase_video_player';
  }
}

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

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