From c9295477fd69066b539aa58c3842ffa9ac21c590 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 25 Jul 2024 10:30:23 +0200 Subject: [PATCH 1/2] image field caption --- composer.json | 2 +- composer.lock | 22 +++++++++++-------- ...ntity_view_display.node.projet.default.yml | 4 ++-- .../field.field.node.projet.field_photo.yml | 2 +- ...age_variant.node_view-panels_variant-5.yml | 6 +++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 8ed3758..a4393f8 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "drupal/geofield": "^1.36", "drupal/honeypot": "^2.1", "drupal/image_delta_formatter": "^1.1", - "drupal/image_field_caption": "^1.1", + "drupal/image_field_caption": "^2.0", "drupal/leaflet": "^10.2", "drupal/leaflet_more_maps": "^2.1", "drupal/leaflet_more_markers": "^1.1", diff --git a/composer.lock b/composer.lock index 722589e..6bbf59a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d7e66c13bb2cc1a87dcc389c5ddc751c", + "content-hash": "8caf5041bf39fd16d88787901df64c6c", "packages": [ { "name": "alchemy/zippy", @@ -5898,26 +5898,26 @@ }, { "name": "drupal/image_field_caption", - "version": "1.2.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://git.drupalcode.org/project/image_field_caption.git", - "reference": "8.x-1.2" + "reference": "2.0.1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/image_field_caption-8.x-1.2.zip", - "reference": "8.x-1.2", - "shasum": "ea4705e97d8b13257507f2013e16a7ba244a4298" + "url": "https://ftp.drupal.org/files/projects/image_field_caption-2.0.1.zip", + "reference": "2.0.1", + "shasum": "053e1ccfc638b3b2cd5c59c3c6a053e4e5041183" }, "require": { - "drupal/core": "^8 || ^9" + "drupal/core": "^9 || ^10" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.2", - "datestamp": "1651684811", + "version": "2.0.1", + "datestamp": "1705443097", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -5945,6 +5945,10 @@ "name": "iStryker", "homepage": "https://www.drupal.org/user/303676" }, + { + "name": "RobLoach", + "homepage": "https://www.drupal.org/user/61114" + }, { "name": "tyler.frankenstein", "homepage": "https://www.drupal.org/user/150680" diff --git a/config/sync/core.entity_view_display.node.projet.default.yml b/config/sync/core.entity_view_display.node.projet.default.yml index 9f255e3..100ea31 100644 --- a/config/sync/core.entity_view_display.node.projet.default.yml +++ b/config/sync/core.entity_view_display.node.projet.default.yml @@ -26,7 +26,7 @@ dependencies: - entity_reference_revisions - file - geofield - - image + - image_field_caption - link - manage_display - options @@ -128,7 +128,7 @@ content: weight: 106 region: content field_photo: - type: image + type: image_caption label: above settings: image_link: '' diff --git a/config/sync/field.field.node.projet.field_photo.yml b/config/sync/field.field.node.projet.field_photo.yml index a05edc9..4df3d06 100644 --- a/config/sync/field.field.node.projet.field_photo.yml +++ b/config/sync/field.field.node.projet.field_photo.yml @@ -43,6 +43,6 @@ settings: width: null height: null caption: '' - caption_field: 0 + caption_field: 1 caption_field_required: 0 field_type: image diff --git a/config/sync/page_manager.page_variant.node_view-panels_variant-5.yml b/config/sync/page_manager.page_variant.node_view-panels_variant-5.yml index aa9481e..7f2086b 100644 --- a/config/sync/page_manager.page_variant.node_view-panels_variant-5.yml +++ b/config/sync/page_manager.page_variant.node_view-panels_variant-5.yml @@ -62,12 +62,14 @@ variant_settings: context_mapping: entity: node formatter: - type: image + type: image_caption weight: 0 label: hidden settings: - image_link: '' image_style: wide + image_link: '' + image_loading: + attribute: lazy third_party_settings: { } region: top weight: -5 From 6734b96a40dff0b31f27a3a9afbc6770d661c082 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 5 Sep 2024 10:55:35 +0200 Subject: [PATCH 2/2] image field migrate alt to caption drush script --- caption-drush-script.php | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 caption-drush-script.php diff --git a/caption-drush-script.php b/caption-drush-script.php new file mode 100644 index 0000000..cc70f5e --- /dev/null +++ b/caption-drush-script.php @@ -0,0 +1,47 @@ +output()->writeln("Hello world!"); +// $this->output()->writeln("The extra options/arguments to this command were:"); +// $this->output()->writeln(print_r($extra, true)); + +// +// We can check which site was bootstrapped via +// the '@self' alias, which is defined only if +// there is a bootstrapped site. +// +$self = Drush::aliasManager()->getSelf();; +if (!$self->hasRoot()) { + $this->output()->writeln('No bootstrapped site.'); +} +else { + $this->output()->writeln('The following site is bootstrapped:'); + $this->output()->writeln(print_r($self->legacyRecord(), true)); + + // $nids = \Drupal::entityQuery('node')->condition('type','projet')->execute(); + $nodes = \Drupal::entityTypeManager()->getStorage('node') + ->loadByProperties(['type' => 'projet']); + + foreach ($nodes as $nid => $node) { + /** @var Drupal\file\Plugin\Field\FieldType\FileFieldItemList $field_photo */ + $field_photo = $node->get('field_photo'); + $itemlist = $field_photo->getValue(); + /** @var Drupal\image_field_caption\ImageCaptionItem $field_item */ + foreach ($itemlist as $key => $field_item) { + if (!empty($field_item['alt']) && (!isset($field_item['caption']) || empty($field_item['caption']))) { + $field_item['image_field_caption']['value'] = $field_item['alt']; + $field_item['image_field_caption']['format'] = 'plain_text'; + $itemlist[$key] = $field_item; + } + } + // $field_photo->setValue($itemlist); + $node->set('field_photo', $itemlist); + $node->save(); + } +} +