diff --git a/core/modules/media/media.api.php b/core/modules/media/media.api.php index 6030ccb84d..48ffe5d4c3 100644 --- a/core/modules/media/media.api.php +++ b/core/modules/media/media.api.php @@ -11,7 +11,7 @@ */ /** - * Alter the information provided in \Drupal\media\Annotation\MediaHandler. + * Alters the information provided in \Drupal\media\Annotation\MediaHandler. * * @param array $handlers * The array of media handler plugin definitions, keyed by plugin ID. diff --git a/core/modules/media/media.install b/core/modules/media/media.install index c674daf5f5..3d0e753a94 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -11,15 +11,47 @@ function media_install() { $source = drupal_get_path('module', 'media') . '/images/icons'; $destination = \Drupal::config('media.settings')->get('icon_base_uri'); - if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { - throw new \RuntimeException("Unable to create directory $destination."); - } + file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/'); foreach ($files as $file) { $result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE); - if (!$result) { - throw new \RuntimeException("Unable to copy {$file->uri} to $destination."); + } +} + +/** + * Implements hook_requirements(). + */ +function media_requirements($phase) { + $requirements = []; + if ($phase == 'install') { + $source = drupal_get_path('module', 'media') . '/images/icons'; + $destination = 'public://media-icons/generic'; + file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + $is_writable = is_writable($destination); + $is_directory = is_dir($destination); + $error = ''; + if (!$is_writable || !$is_directory) { + if (!$is_directory) { + $error = t('The directory %directory does not exist.', ['%directory' => $destination]); + } + else { + $error = t('The directory %directory is not writable.', ['%directory' => $destination]); + } + $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the online handbook.', [':handbook_url' => 'https://www.drupal.org/server-permissions']); + if (!empty($error)) { + $description = [ + '#type' => 'inline_template', + '#template' => '{{ error }} {{ description }}', + '#context' => [ + 'error' => $error, + 'description' => $description, + ], + ]; + $requirements['media']['description'] = $description; + $requirements['media']['severity'] = REQUIREMENT_ERROR; + } } } + return $requirements; } diff --git a/core/modules/media/media.links.menu.yml b/core/modules/media/media.links.menu.yml index 0ab03d2021..33dd67978c 100644 --- a/core/modules/media/media.links.menu.yml +++ b/core/modules/media/media.links.menu.yml @@ -4,8 +4,3 @@ entity.media_type.collection: description: 'Manage media types.' route_name: entity.media_type.collection -entity.media.add: - title: 'Add media' - parent: entity.media.collection - description: 'Add new media.' - route_name: entity.media.add_page diff --git a/core/modules/media/media.module b/core/modules/media/media.module index 4571e5322c..6bc73821d6 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -43,7 +43,6 @@ function media_theme() { return [ 'media' => [ 'render element' => 'elements', - 'template' => 'media', ], ]; } diff --git a/core/modules/media/src/MediaForm.php b/core/modules/media/src/MediaForm.php index 6d4d2d1f46..89c178fd86 100644 --- a/core/modules/media/src/MediaForm.php +++ b/core/modules/media/src/MediaForm.php @@ -11,20 +11,6 @@ class MediaForm extends ContentEntityForm { /** - * Default settings for this media type. - * - * @var array - */ - protected $settings; - - /** - * The entity being used by this form. - * - * @var \Drupal\media\MediaInterface - */ - protected $entity; - - /** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php index 33021a689f..9210e96e49 100644 --- a/core/modules/media/src/MediaTypeForm.php +++ b/core/modules/media/src/MediaTypeForm.php @@ -33,13 +33,6 @@ class MediaTypeForm extends EntityForm { protected $entityFieldManager; /** - * The entity being created or modified. - * - * @var \Drupal\media\MediaTypeInterface - */ - protected $entity; - - /** * Constructs a new class instance. * * @param \Drupal\media\MediaHandlerManager $handler_manager