This commit is contained in:
2024-10-04 09:16:38 +02:00
6 changed files with 68 additions and 15 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
//
// This example demonstrates how to write a drush
// script. These scripts are run with the php:script command.
//
use Drush\Drush;
// $this->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();
}
}
+1 -1
View File
@@ -29,7 +29,7 @@
"drupal/geofield": "^1.36", "drupal/geofield": "^1.36",
"drupal/honeypot": "^2.1", "drupal/honeypot": "^2.1",
"drupal/image_delta_formatter": "^1.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": "^10.2",
"drupal/leaflet_more_maps": "^2.1", "drupal/leaflet_more_maps": "^2.1",
"drupal/leaflet_more_markers": "^1.1", "drupal/leaflet_more_markers": "^1.1",
Generated
+13 -9
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d7e66c13bb2cc1a87dcc389c5ddc751c", "content-hash": "8caf5041bf39fd16d88787901df64c6c",
"packages": [ "packages": [
{ {
"name": "alchemy/zippy", "name": "alchemy/zippy",
@@ -5898,26 +5898,26 @@
}, },
{ {
"name": "drupal/image_field_caption", "name": "drupal/image_field_caption",
"version": "1.2.0", "version": "2.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.drupalcode.org/project/image_field_caption.git", "url": "https://git.drupalcode.org/project/image_field_caption.git",
"reference": "8.x-1.2" "reference": "2.0.1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://ftp.drupal.org/files/projects/image_field_caption-8.x-1.2.zip", "url": "https://ftp.drupal.org/files/projects/image_field_caption-2.0.1.zip",
"reference": "8.x-1.2", "reference": "2.0.1",
"shasum": "ea4705e97d8b13257507f2013e16a7ba244a4298" "shasum": "053e1ccfc638b3b2cd5c59c3c6a053e4e5041183"
}, },
"require": { "require": {
"drupal/core": "^8 || ^9" "drupal/core": "^9 || ^10"
}, },
"type": "drupal-module", "type": "drupal-module",
"extra": { "extra": {
"drupal": { "drupal": {
"version": "8.x-1.2", "version": "2.0.1",
"datestamp": "1651684811", "datestamp": "1705443097",
"security-coverage": { "security-coverage": {
"status": "covered", "status": "covered",
"message": "Covered by Drupal's security advisory policy" "message": "Covered by Drupal's security advisory policy"
@@ -5945,6 +5945,10 @@
"name": "iStryker", "name": "iStryker",
"homepage": "https://www.drupal.org/user/303676" "homepage": "https://www.drupal.org/user/303676"
}, },
{
"name": "RobLoach",
"homepage": "https://www.drupal.org/user/61114"
},
{ {
"name": "tyler.frankenstein", "name": "tyler.frankenstein",
"homepage": "https://www.drupal.org/user/150680" "homepage": "https://www.drupal.org/user/150680"
@@ -26,7 +26,7 @@ dependencies:
- entity_reference_revisions - entity_reference_revisions
- file - file
- geofield - geofield
- image - image_field_caption
- link - link
- manage_display - manage_display
- options - options
@@ -128,7 +128,7 @@ content:
weight: 106 weight: 106
region: content region: content
field_photo: field_photo:
type: image type: image_caption
label: above label: above
settings: settings:
image_link: '' image_link: ''
@@ -43,6 +43,6 @@ settings:
width: null width: null
height: null height: null
caption: '' caption: ''
caption_field: 0 caption_field: 1
caption_field_required: 0 caption_field_required: 0
field_type: image field_type: image
@@ -62,12 +62,14 @@ variant_settings:
context_mapping: context_mapping:
entity: node entity: node
formatter: formatter:
type: image type: image_caption
weight: 0 weight: 0
label: hidden label: hidden
settings: settings:
image_link: ''
image_style: wide image_style: wide
image_link: ''
image_loading:
attribute: lazy
third_party_settings: { } third_party_settings: { }
region: top region: top
weight: -5 weight: -5