PHP code example of slavielle / grabbag
1. Go to this page and download the library: Download slavielle/grabbag library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
slavielle / grabbag example snippets
$result = $node->get('field_media_image')->first()->get('entity')->getTarget()->getValue()->get('field_image')->entity->getFileUri()
echo $result;
$result = Grabbag::grab($node, 'get("field_media_image")/first/get("entity")/target/value/get("field_image")/entity/fileUri');
echo $result;
$result = Grabbag::grab($node, 'get("field_media_image")/%any/get("entity")/target/value/get("field_image")/entity/fileUri');
var_dump($result);
$node->get('field_media_image')
[
"my/image/1.jpg",
"my/image/2.jpg",
"my/image/3.jpg",
"my/image/4.jpg"
]
$result = Grabbag::grab($node, [
'content-title:get("title").value',
'images:get("field_media_image")/%any/get("entity")/target/value/get("field_image")' => [
'uri:entity/fileUri',
'alt:alt'
]
]);
var_dump($result);
[
'content-title' => 'My node title',
'images' => [
[
'uri' => "my/image/1.jpg",
'alt' => "My image 1 alt"
],
[
'uri' => "my/image/2.jpg",
'alt' => "My image 2 alt"
],
[
'uri' => "my/image/3.jpg",
'alt' => "My image 3 alt"
],
]
]
foreach