Loading media_gallery.info.yml +1 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ name: Media Gallery type: module description: 'A simple gallery of media.' package: media core_version_requirement: ^8 || ^9 || ^10 core_version_requirement: ^9.3 || ^10 dependencies: - drupal:text - drupal:media_library (>= 8.7) Loading media_gallery.install +4 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ use Drupal\Core\Config\FileStorage; /** * Implements hook_uninstall(). */ function media_gallery_uninstall() { function media_gallery_uninstall(): void { \Drupal::configFactory()->getEditable('image.style.media_gallery_image')->delete(); \Drupal::configFactory()->getEditable('core.entity_view_mode.media.media_colorbox')->delete(); \Drupal::configFactory()->getEditable('core.entity_view_display.media.image.media_colorbox')->delete(); Loading @@ -23,8 +23,8 @@ function media_gallery_uninstall() { * @param string $config_name * Config name. */ function _media_gallery_update_config($config_name) { $config_path = drupal_get_path('module', 'media_gallery') . '/config/install'; function _media_gallery_update_config(string $config_name): void { $config_path = \Drupal::service('extension.list.module')->getPath('media_gallery') . '/config/install'; $source = new FileStorage($config_path); $config_storage = \Drupal::service('config.storage'); $config_storage->write($config_name, $source->read($config_name)); Loading @@ -33,6 +33,6 @@ function _media_gallery_update_config($config_name) { /** * Update "All Galleries view". */ function media_gallery_update_8101(&$sandbox) { function media_gallery_update_8101(): void { _media_gallery_update_config('views.view.media_galleries'); } media_gallery.module +4 −4 Original line number Diff line number Diff line Loading @@ -11,14 +11,14 @@ use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ function media_gallery_help($route_name, RouteMatchInterface $route_match) { function media_gallery_help(string $route_name, RouteMatchInterface $route_match): string { return ''; } /** * Implements hook_theme(). */ function media_gallery_theme() { function media_gallery_theme(): array { return [ 'media_gallery' => [ 'render element' => 'elements', Loading @@ -40,7 +40,7 @@ function media_gallery_theme() { * information and any fields attached to the entity. * - attributes: HTML attributes for the containing element. */ function template_preprocess_media_gallery(array &$variables) { function template_preprocess_media_gallery(array &$variables): void { $variables['media_gallery'] = $variables['elements']['#media_gallery']; foreach (Element::children($variables['elements']) as $key) { Loading @@ -51,7 +51,7 @@ function template_preprocess_media_gallery(array &$variables) { /** * Implements hook_theme_suggestions_HOOK(). */ function media_gallery_theme_suggestions_media_gallery(array $variables) { function media_gallery_theme_suggestions_media_gallery(array $variables): array { $suggestions = []; $media_gallery = $variables['elements']['#media_gallery']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); Loading modules/media_gallery_import/src/Form/MediaGalleryImportForm.php +10 −14 Original line number Diff line number Diff line Loading @@ -17,17 +17,13 @@ class MediaGalleryImportForm extends FormBase { /** * FileSystemInterface. * * @var \Drupal\Core\File\FileSystemInterface */ private $fileSystemInterface; private FileSystemInterface $fileSystemInterface; /** * EntityTypeManagerInterface. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ private $entityTypeManager; private EntityTypeManagerInterface $entityTypeManager; /** * Constructs a new MediaGalleryImportForm object. Loading Loading @@ -92,9 +88,9 @@ class MediaGalleryImportForm extends FormBase { $import_dir_path = $this->fileSystemInterface->realpath($import_dir); $galleries_storage = $this->entityTypeManager->getStorage('media_gallery'); $galleries_csv = fopen($import_dir_path . '/galleries.csv', 'r'); $galleries_csv = \fopen($import_dir_path . '/galleries.csv', 'r'); while (($galleries_data = fgetcsv($galleries_csv, 0, ';')) !== FALSE) { while (($galleries_data = \fgetcsv($galleries_csv, 0, ';')) !== FALSE) { $gallery_id = $galleries_data[0]; $gallery_title = $galleries_data[1]; $gallery_desc = $galleries_data[2]; Loading @@ -108,20 +104,20 @@ class MediaGalleryImportForm extends FormBase { $gallery_dir = $import_dir . '/' . $gallery_id; $gallery_dir_path = $this->fileSystemInterface->realpath($gallery_dir); $gallery_csv = fopen($gallery_dir_path . '/gallery.csv', 'r'); $files_dir = 'public://' . date('Y') . '-' . date('m'); $gallery_csv = \fopen($gallery_dir_path . '/gallery.csv', 'r'); $files_dir = 'public://' . \date('Y') . '-' . \date('m'); if (!$this->fileSystemInterface->prepareDirectory($files_dir, FileSystemInterface::CREATE_DIRECTORY)) { $this->messenger()->addMessage($this->t('Can not create directory to import files! Aborting.')); return; } while (($gallery_data = fgetcsv($gallery_csv, 255, ';')) !== FALSE) { while (($gallery_data = \fgetcsv($gallery_csv, 255, ';')) !== FALSE) { $filename = $gallery_data[0]; $file_title = $gallery_data[1]; $file_path = $gallery_dir . '/' . $filename; $file_new_path = $files_dir . '/' . $filename; copy($file_path, $file_new_path); \copy($file_path, $file_new_path); // Create file entity. $file = File::create([ Loading @@ -147,10 +143,10 @@ class MediaGalleryImportForm extends FormBase { $gallery->save(); } fclose($gallery_csv); \fclose($gallery_csv); } fclose($galleries_csv); \fclose($galleries_csv); $this->messenger()->addMessage($this->t('Your galleries were imported!')); } Loading src/Entity/MediaGallery.php +18 −18 Original line number Diff line number Diff line Loading @@ -71,14 +71,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function getTitle() { public function getTitle(): string { return $this->get('title')->value; } /** * {@inheritdoc} */ public function setTitle($title) { public function setTitle($title): MediaGalleryInterface { $this->set('title', $title); return $this; } Loading @@ -86,14 +86,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function isEnabled() { public function isEnabled(): bool { return (bool) $this->get('status')->value; } /** * {@inheritdoc} */ public function setStatus($status) { public function setStatus($status): MediaGalleryInterface { $this->set('status', $status); return $this; } Loading @@ -101,14 +101,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function getCreatedTime() { public function getCreatedTime(): int { return $this->get('created')->value; } /** * {@inheritdoc} */ public function setCreatedTime($timestamp) { public function setCreatedTime($timestamp): MediaGalleryInterface { $this->set('created', $timestamp); return $this; } Loading Loading @@ -151,8 +151,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { $fields = parent::baseFieldDefinitions($entity_type); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('The title of the media gallery entity.')) ->setLabel(\t('Title')) ->setDescription(\t('The title of the media gallery entity.')) ->setRequired(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', [ Loading @@ -168,8 +168,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['description'] = BaseFieldDefinition::create('text_long') ->setLabel(t('Description')) ->setDescription(t('A description of the media gallery.')) ->setLabel(\t('Description')) ->setDescription(\t('A description of the media gallery.')) ->setDisplayOptions('form', [ 'type' => 'text_textarea', 'weight' => 1, Loading @@ -183,7 +183,7 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['images'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Gallery images')) ->setLabel(\t('Gallery images')) ->setSetting('target_type', 'media') ->SetCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setDisplayConfigurable('form', FALSE) Loading @@ -202,8 +202,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ]); $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Author')) ->setDescription(t('The user ID of the media gallery author.')) ->setLabel(\t('Author')) ->setDescription(\t('The user ID of the media gallery author.')) ->setSetting('target_type', 'user') ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete', Loading @@ -223,8 +223,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Authored on')) ->setDescription(t('The time that the media gallery was created.')) ->setLabel(\t('Authored on')) ->setDescription(\t('The time that the media gallery was created.')) ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'hidden', Loading @@ -238,11 +238,11 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the media gallery was last edited.')); ->setLabel(\t('Changed')) ->setDescription(\t('The time that the media gallery was last edited.')); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Published')) ->setLabel(\t('Published')) ->setDefaultValue(TRUE) ->setSetting('on_label', 'Published') ->setDisplayOptions('form', [ Loading Loading
media_gallery.info.yml +1 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ name: Media Gallery type: module description: 'A simple gallery of media.' package: media core_version_requirement: ^8 || ^9 || ^10 core_version_requirement: ^9.3 || ^10 dependencies: - drupal:text - drupal:media_library (>= 8.7) Loading
media_gallery.install +4 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ use Drupal\Core\Config\FileStorage; /** * Implements hook_uninstall(). */ function media_gallery_uninstall() { function media_gallery_uninstall(): void { \Drupal::configFactory()->getEditable('image.style.media_gallery_image')->delete(); \Drupal::configFactory()->getEditable('core.entity_view_mode.media.media_colorbox')->delete(); \Drupal::configFactory()->getEditable('core.entity_view_display.media.image.media_colorbox')->delete(); Loading @@ -23,8 +23,8 @@ function media_gallery_uninstall() { * @param string $config_name * Config name. */ function _media_gallery_update_config($config_name) { $config_path = drupal_get_path('module', 'media_gallery') . '/config/install'; function _media_gallery_update_config(string $config_name): void { $config_path = \Drupal::service('extension.list.module')->getPath('media_gallery') . '/config/install'; $source = new FileStorage($config_path); $config_storage = \Drupal::service('config.storage'); $config_storage->write($config_name, $source->read($config_name)); Loading @@ -33,6 +33,6 @@ function _media_gallery_update_config($config_name) { /** * Update "All Galleries view". */ function media_gallery_update_8101(&$sandbox) { function media_gallery_update_8101(): void { _media_gallery_update_config('views.view.media_galleries'); }
media_gallery.module +4 −4 Original line number Diff line number Diff line Loading @@ -11,14 +11,14 @@ use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ function media_gallery_help($route_name, RouteMatchInterface $route_match) { function media_gallery_help(string $route_name, RouteMatchInterface $route_match): string { return ''; } /** * Implements hook_theme(). */ function media_gallery_theme() { function media_gallery_theme(): array { return [ 'media_gallery' => [ 'render element' => 'elements', Loading @@ -40,7 +40,7 @@ function media_gallery_theme() { * information and any fields attached to the entity. * - attributes: HTML attributes for the containing element. */ function template_preprocess_media_gallery(array &$variables) { function template_preprocess_media_gallery(array &$variables): void { $variables['media_gallery'] = $variables['elements']['#media_gallery']; foreach (Element::children($variables['elements']) as $key) { Loading @@ -51,7 +51,7 @@ function template_preprocess_media_gallery(array &$variables) { /** * Implements hook_theme_suggestions_HOOK(). */ function media_gallery_theme_suggestions_media_gallery(array $variables) { function media_gallery_theme_suggestions_media_gallery(array $variables): array { $suggestions = []; $media_gallery = $variables['elements']['#media_gallery']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); Loading
modules/media_gallery_import/src/Form/MediaGalleryImportForm.php +10 −14 Original line number Diff line number Diff line Loading @@ -17,17 +17,13 @@ class MediaGalleryImportForm extends FormBase { /** * FileSystemInterface. * * @var \Drupal\Core\File\FileSystemInterface */ private $fileSystemInterface; private FileSystemInterface $fileSystemInterface; /** * EntityTypeManagerInterface. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ private $entityTypeManager; private EntityTypeManagerInterface $entityTypeManager; /** * Constructs a new MediaGalleryImportForm object. Loading Loading @@ -92,9 +88,9 @@ class MediaGalleryImportForm extends FormBase { $import_dir_path = $this->fileSystemInterface->realpath($import_dir); $galleries_storage = $this->entityTypeManager->getStorage('media_gallery'); $galleries_csv = fopen($import_dir_path . '/galleries.csv', 'r'); $galleries_csv = \fopen($import_dir_path . '/galleries.csv', 'r'); while (($galleries_data = fgetcsv($galleries_csv, 0, ';')) !== FALSE) { while (($galleries_data = \fgetcsv($galleries_csv, 0, ';')) !== FALSE) { $gallery_id = $galleries_data[0]; $gallery_title = $galleries_data[1]; $gallery_desc = $galleries_data[2]; Loading @@ -108,20 +104,20 @@ class MediaGalleryImportForm extends FormBase { $gallery_dir = $import_dir . '/' . $gallery_id; $gallery_dir_path = $this->fileSystemInterface->realpath($gallery_dir); $gallery_csv = fopen($gallery_dir_path . '/gallery.csv', 'r'); $files_dir = 'public://' . date('Y') . '-' . date('m'); $gallery_csv = \fopen($gallery_dir_path . '/gallery.csv', 'r'); $files_dir = 'public://' . \date('Y') . '-' . \date('m'); if (!$this->fileSystemInterface->prepareDirectory($files_dir, FileSystemInterface::CREATE_DIRECTORY)) { $this->messenger()->addMessage($this->t('Can not create directory to import files! Aborting.')); return; } while (($gallery_data = fgetcsv($gallery_csv, 255, ';')) !== FALSE) { while (($gallery_data = \fgetcsv($gallery_csv, 255, ';')) !== FALSE) { $filename = $gallery_data[0]; $file_title = $gallery_data[1]; $file_path = $gallery_dir . '/' . $filename; $file_new_path = $files_dir . '/' . $filename; copy($file_path, $file_new_path); \copy($file_path, $file_new_path); // Create file entity. $file = File::create([ Loading @@ -147,10 +143,10 @@ class MediaGalleryImportForm extends FormBase { $gallery->save(); } fclose($gallery_csv); \fclose($gallery_csv); } fclose($galleries_csv); \fclose($galleries_csv); $this->messenger()->addMessage($this->t('Your galleries were imported!')); } Loading
src/Entity/MediaGallery.php +18 −18 Original line number Diff line number Diff line Loading @@ -71,14 +71,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function getTitle() { public function getTitle(): string { return $this->get('title')->value; } /** * {@inheritdoc} */ public function setTitle($title) { public function setTitle($title): MediaGalleryInterface { $this->set('title', $title); return $this; } Loading @@ -86,14 +86,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function isEnabled() { public function isEnabled(): bool { return (bool) $this->get('status')->value; } /** * {@inheritdoc} */ public function setStatus($status) { public function setStatus($status): MediaGalleryInterface { $this->set('status', $status); return $this; } Loading @@ -101,14 +101,14 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { /** * {@inheritdoc} */ public function getCreatedTime() { public function getCreatedTime(): int { return $this->get('created')->value; } /** * {@inheritdoc} */ public function setCreatedTime($timestamp) { public function setCreatedTime($timestamp): MediaGalleryInterface { $this->set('created', $timestamp); return $this; } Loading Loading @@ -151,8 +151,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { $fields = parent::baseFieldDefinitions($entity_type); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('The title of the media gallery entity.')) ->setLabel(\t('Title')) ->setDescription(\t('The title of the media gallery entity.')) ->setRequired(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', [ Loading @@ -168,8 +168,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['description'] = BaseFieldDefinition::create('text_long') ->setLabel(t('Description')) ->setDescription(t('A description of the media gallery.')) ->setLabel(\t('Description')) ->setDescription(\t('A description of the media gallery.')) ->setDisplayOptions('form', [ 'type' => 'text_textarea', 'weight' => 1, Loading @@ -183,7 +183,7 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['images'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Gallery images')) ->setLabel(\t('Gallery images')) ->setSetting('target_type', 'media') ->SetCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setDisplayConfigurable('form', FALSE) Loading @@ -202,8 +202,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ]); $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Author')) ->setDescription(t('The user ID of the media gallery author.')) ->setLabel(\t('Author')) ->setDescription(\t('The user ID of the media gallery author.')) ->setSetting('target_type', 'user') ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete', Loading @@ -223,8 +223,8 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Authored on')) ->setDescription(t('The time that the media gallery was created.')) ->setLabel(\t('Authored on')) ->setDescription(\t('The time that the media gallery was created.')) ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'hidden', Loading @@ -238,11 +238,11 @@ class MediaGallery extends ContentEntityBase implements MediaGalleryInterface { ->setDisplayConfigurable('view', TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the media gallery was last edited.')); ->setLabel(\t('Changed')) ->setDescription(\t('The time that the media gallery was last edited.')); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Published')) ->setLabel(\t('Published')) ->setDefaultValue(TRUE) ->setSetting('on_label', 'Published') ->setDisplayOptions('form', [ Loading