X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmedia_entity%2Fmedia_entity.module;h=9012a8639ac3a2e7cbc718ff1a25802ce677dde4;hb=9e65bae52407293a5182f19dc57b5628b09e92f4;hp=d54f773417bc00219c7907cc007bb5934ffa89e1;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/modules/contrib/media_entity/media_entity.module b/web/modules/contrib/media_entity/media_entity.module index d54f77341..9012a8639 100644 --- a/web/modules/contrib/media_entity/media_entity.module +++ b/web/modules/contrib/media_entity/media_entity.module @@ -5,80 +5,53 @@ * Provides media entities. */ -use Drupal\Core\Routing\RouteMatchInterface; +// This empty file needs to be here so that drush commands that automatically +// include .module files on enabled modules don't complain. -/** - * Implements hook_help(). - */ -function media_entity_help($route_name, RouteMatchInterface $route_match) { - switch ($route_name) { - case 'help.page.media_entity': - $output = '

' . t('About') . '

'; - $output .= '

' . t('The Media Entity module provides a "base" entity for media. This is a very basic entity which can reference to all kinds of media-objects (local files, YouTube videos, Tweets, Instagram photos, ...). Media entity provides a relation between your website and the media resource. You can reference to/use this entity within any other entity on your site. For more information, see the online documentation for the Media Entity module.', - [ - ':media_entity_url' => 'https://www.drupal.org/project/media_entity', - ':media_entity_handbook' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/media_entity/intro.html', - ]) . '

'; - $output .= '

' . t('Uses') . '

'; - $output .= '

' . t('For detailed information about the usage of this module please refer to the official documentation.', - [ - ':media_entity_handbook' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/media_entity/intro.html', - ]) . '

'; - - return $output; - } -} - -/** - * Implements hook_theme(). - */ -function media_entity_theme() { - return [ - 'media' => [ - 'render element' => 'elements', - 'file' => 'media_entity.theme.inc', - 'template' => 'media', - ], - ]; -} +use Drupal\Core\Config\Entity\ConfigEntityType; +use Drupal\Core\Entity\ContentEntityType; +use Drupal\media_entity\Media; +use Drupal\media_entity\MediaBundle; /** - * Implements hook_theme_suggestions_HOOK(). + * Implements hook_entity_type_build(). */ -function media_entity_theme_suggestions_media(array $variables) { - $suggestions = []; - $media = $variables['elements']['#media']; - $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); - - $suggestions[] = 'media__' . $sanitized_view_mode; - $suggestions[] = 'media__' . $media->bundle(); - $suggestions[] = 'media__' . $media->bundle() . '__' . $sanitized_view_mode; - $suggestions[] = 'media__' . $media->id(); - $suggestions[] = 'media__' . $media->id() . '__' . $sanitized_view_mode; - - return $suggestions; -} - -/** - * Copy the media file icons to files directory for use with image styles. - * - * @param string $source - * Source folder. - * @param string $destination - * Destination folder. - * - * @throws Exception - */ -function media_entity_copy_icons($source, $destination) { - if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { - throw new Exception("Unable to create directory $destination."); - } - - $files = file_scan_directory($source, '/.*\.(png|jpg)$/'); - foreach ($files as $file) { - $result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE); - if (!$result) { - throw new Exception("Unable to copy {$file->uri} to $destination."); - } +function media_entity_entity_type_build(array &$entity_types) { + if (!\Drupal::moduleHandler()->moduleExists('media')) { + $entity_types['media'] = new ContentEntityType([ + 'id' => 'media', + 'provider' => 'media_entity', + 'class' => Media::class, + 'base_table' => 'media', + 'data_table' => 'media_field_data', + 'revision_table' => 'media_revision', + 'revision_data_table' => 'media_field_revision', + 'translatable' => TRUE, + 'entity_keys' => [ + 'id' => 'mid', + 'revision' => 'vid', + 'bundle' => 'bundle', + 'label' => 'name', + 'langcode' => 'langcode', + 'uuid' => 'uuid', + 'published' => 'status', + ], + 'revision_metadata_keys' => [ + 'revision_user' => 'revision_user', + 'revision_created' => 'revision_created', + 'revision_log_message' => 'revision_log_message', + ], + 'bundle_entity_type' => 'media_bundle', + ]); + $entity_types['media_bundle'] = new ConfigEntityType([ + 'id' => 'media_bundle', + 'provider' => 'media_entity', + 'class' => MediaBundle::class, + 'bundle_of' => 'media', + 'entity_keys' => [ + 'id' => 'id', + 'label' => 'label', + ], + ]); } }