See whether an array of elements are a subset, in terms of a single property, of another array of objects, and in the same order, in PHP
Some preliminaries, just to get the data we’re going to be comparing…
drupal 8 taxonomy term load vocabulary
but that says use TermInterface::bundle() instead.
php get a single value from a traversable
https://www.php.net/manual/en/function.current.php
drupal 8 taxonomy documentation
drupal 8 get entity type of an entity
I gotta say it: doing this huge lift to have object oriented code and then passing around objects that can’t even tell the code they arrive at what the hell they are is like building a giant electronic mail sorting system and forcing people to learn to write bar codes, but the mail sorting system can’t actually read addresses and you have to take things to the destination yourself.
To be fair in Drupal 8 once an entity is fully loaded you are supposed to be able to get the entity type, but your code always has to load the entity it seems to have a full entity, and to load an entity you need… you guessed it, the entity type! :facepalm:
So:
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('vocab_name');
current($terms)->getEntityType();
PHP Error: Call to undefined method stdClass::getEntityType().
Handed that entity, knowing the entity but not what type, you’re out of luck.
You have to know the entity type to load it fully:
$loaded_term = \Drupal::entityManager()->getStorage(’taxonomy_term’)->load($basic_term->tid); $entity_type = $loaded_term->getEntityType(); // And finally, to get what you very likely actually want: $entity_type->get(‘id’); // Gives back “taxonomy_term” — but you most certainly already knew that.
The Entity Reference Formatter gets around this conundrum by asking the field what the target entity is. I can do that too, in this case, but we were so close to having objects that could be passed around containing all the information anything else in Drupal would need to interact with them. Gah.
- php is sequential
- compare array to ordered array
php get item position in array php compare one property of complex objects array keys for object php array_keys for array of objects php php find array location of an object in an array of objects
Ah, it looks like array_filter
can basically be used as a combined array_keys
/array_search
that takes a callback function.
Ah no we need more. There’s no value given to array_filter
php array_filter with callback that takes a value
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('findit_day_of_week');
$label = "Sunday"
$firstmatch = array_filter($terms, function($term) use ($label) { return $term->name == $label; });
=> [
{#5025
+"tid": "94",
+"revision_id": "56",
+"vid": "findit_day_of_week",
+"langcode": "en",
+"status": "1",
+"name": "Sunday",
+"description__value": null,
+"description__format": null,
+"weight": "0",
+"changed": "1568664240",
+"default_langcode": "1",
+"revision_translation_affected": "1",
+"depth": 0,
+"parents": [
"0",
],
},
]
Wow that worked! Now, why can’t i see explicit keys for that array?
- php force array to have keys
- php see explicit keys for an array
OK if i use key()
it gives a result.
key($firstmatch)
=> 0
With a label of Tuesday it gives a key number as expected.
key($firstmatch); => 2
- reorder an array so a given key is first php
- array go to a given key php
- php go directly to specific key in an array
Nothing? OK fine i don’t need to do it that way, heck, i don’t even want to do it that way.
php using next in a foreach
So next returns the current item and advances? Nah it returns the next:
current($terms); // Gives object for Sunday.
next($terms); // Gives object for Monday.
current($terms); // Gives object for Monday.
next($terms); // Gives object for Tuesday.
next($terms); // Gives object for Wednesday.
// etc.
php mix numeric and alpha array keys
Yeah removing our alpha key will bring it back to being a regular associative array.
Building render arrays that have render arrays in strings
UPDATE: Do not, repeat: DO NOT, use the render array ‘placeholders’ capability for this task. It is meant specifically to allow rendering to be delayed until possibly after page load even and it is very difficult to use and all i know is everything broke.
drupal 8 token replacement in render arrays keeping link types separate in text in render arrays drupal 8
From the [documentation on placeholders in render arrays]:
$build['my_element'] = [
'#attached' => [
'placeholders' => [
'@foo' => 'replacement',
],
],
'#markup' => [
'Something about @foo',
],
];
then #markup
would end up containing ‘Something about replacement’.
It continues:
Note that each placeholder value can itself be a render array, which will be rendered, and any cache tags generated during rendering will be added to the cache tags for the markup.
I’m not sure if my use of it fits the intended use case or will work for me; i’m not really trying to allow replacement later but just construct my render output in the most flexibly modifiable way. (It’s the markup part i’d want people to replace, while the tokens remain the same, in fact!) But anyhow it will keep things separated in my code, and maybe there’s another way to keep this all separate and re-mixable.
get bundle label for entity
In the context of what i was doing:
$target_bundle = $this->fieldDefinition->getTargetBundle();
$target_bundle_label = \Drupal::entityTypeManager()->getStorage($field_definition->getTargetEntityTypeId())->load($target_bundle)->label();
A shorter example is here https://drupal.stackexchange.com/questions/187980/how-to-get-bundle-label-from-entity#187983
Except that was totally wrong for what i was trying to do:
FieldDefinitionInterface::getTargetBundle() answers “as a field,
-
which bundle are you attached to?".
And i’m looking for the bundle of the target
So we need this (figured out without an IDE; don’t try this at home though kids, get an IDE):
$handler_settings = $this->fieldDefinition->getSetting('handler_settings');
$vocabulary_id = current($handler_settings['target_bundles']);
drupal 8 get field label
In this situation:
$field_name = $field_definition->getLabel();
If you have a node or entity, which is more commonly the case, see https://drupal.stackexchange.com/questions/201064/how-do-i-get-the-field-label-from-a-node-object#201065
Gaaaah so close i have the right sequence but my attempts to turn it into markup are failing horribly?
if (count($sequence) >= $minimum_sequence) {
$last_element = end($sequence);
$first_element = reset($sequence);
$connecting_word_markup = [
'#plain_text' => $connecting_word,
];
$inotherwords[$id] = [
'#markup' => [
"@first_element @connecting_word @last_element",
],
'#attached' => [
'placeholders' => [
'@first_element' => $first_element,
'@connecting_word' => $connecting_word_markup,
'@last_element' => $last_element,
],
],
];
}
Again, don’t do that. It’ll lead to errors like the below. Scroll past the error for a better approach.
ep 19 01:40:36 findit-dev drupal: http://findit-dev.test|1568857236|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Warning: strlen() expects parameter 1 to be string, array given in Drupal\Component\Utility\Unicode::validateUtf8() (line 599 of /var/www/drupal/web/core/lib/Drupal/Component/Utility/Unicode.php) #0 /var/www/drupal/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(2, 'strlen() expect...', '/var/www/drupal...', 599, Array)#012#1 [internal function]: _drupal_error_handler(2, 'strlen() expect...', '/var/www/drupal...', 599, Array)#012#2 /var/www/drupal/web/core/lib/Drupal/Component/Utility/Unicode.php(599): strlen(Array)#012#3 /var/www/drupal/web/core/lib/Drupal/Component/Utility/Xss.php(63): Drupal\Component\Utility\Unicode::validateUtf8(Array)#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(753): Drupal\Component\Utility\Xss::filter(Array, Array)#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(384): Drupal\Core\Render\Renderer->ensureMarkupIsSafe(Array)#012#6 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#7 /var/www/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render(Array)#012#8 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_renderables.html.twig_WMtxrvcEU8n0N-73nZNvN8jKt/V4U04-Z-aq4q_68cUNoEXm2GbjfFnzZCdW6kpd151R4.php(122): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)#012#9 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_field.html.twig_1nF_gLuUjzgK_Z1ARjT-PONS9/QdoSWmziUyyhPPIitWWnoT48OHMOsBW-l-1d9Am9D_M.php(210): __TwigTemplate_a9a17d105d1499cfae9f2eb06d2cb85c3bcd489cd05bfcbd0a2a16a4731aaf59->getmerge_attributes(Object(Drupal\Core\Template\Attribute), Array, 'content')#012#10 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_field.html.twig_1nF_gLuUjzgK_Z1ARjT-PONS9/QdoSWmziUyyhPPIitWWnoT48OHMOsBW-l-1d9Am9D_M.php(88): __TwigTemplate_84f4a8135794fc71b43f28244fc37aee79349b2cb03ee0f60d97fbc38f2671cd->getrender_item(Array, Array, false)#012#11 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_84f4a8135794fc71b43f28244fc37aee79349b2cb03ee0f60d97fbc38f2671cd->doDisplay(Array, Array)#012#12 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#13 /var/www/drupal/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array)#012#14 /var/www/drupal/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render(Array)#012#15 /var/www/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)#012#16 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('field', Array)#012#17 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#18 /var/www/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render(Array)#012#19 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node--findit-program--ful_JAIWVt8GtEvLvjFK9HOD-pDT-/wtcI9mQvF6U9znUdpJqfdXOdW9lFib4xl57rcLqlTWc.php(76): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)#012#20 /var/www/drupal/vendor/twig/twig/src/Template.php(216): __TwigTemplate_44d9812ee70f18d58117fce99a50635d7941eebac20aecaec00cd6299b608db9->block_when_content(Array, Array)#012#21 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node-base--opportunity--f_QvcETz4tqczEpI3hJEK6fh6Fp/MLos6wEWmU3w_4jn693hGYhjFzjBCSJmmsJrVAMaplo.php(213): Twig\Template->displayBlock('when_content', Array, Array)#012#22 /var/www/drupal/vendor/twig/twig/src/Template.php(216): __TwigTemplate_976004d06b2ead812e4dedebed34f1465df49a27146053892be7e9a038c1e90c->block_when(Array, Array)#012#23 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node-base--opportunity--f_QvcETz4tqczEpI3hJEK6fh6Fp/MLos6wEWmU3w_4jn693hGYhjFzjBCSJmmsJrVAMaplo.php(125): Twig\Template->displayBlock('when', Array, Array)#012#24 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_976004d06b2ead812e4dedebed34f1465df49a27146053892be7e9a038c1e90c->doDisplay(Array, Array)#012#25 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#26 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node--findit-program--ful_JAIWVt8GtEvLvjFK9HOD-pDT-/wtcI9mQvF6U9znUdpJqfdXOdW9lFib4xl57rcLqlTWc.php(60): Twig\Template->display(Array, Array)#012#27 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_44d9812ee70f18d58117fce99a50635d7941eebac20aecaec00cd6299b608db9->doDisplay(Array, Array)#012#28 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#29 /var/www/drupal/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array)#012#30 /var/www/drupal/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render(Array)#012#31 /var/www/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)#012#32 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('node', Array)#012#33 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#34 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false)#012#35 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()#012#36 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#37 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))#012#38 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))#012#39 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#40 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#41 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))#012#42 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#43 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#44 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Sym
Sep 19 01:40:36 findit-dev drupal: http://findit-dev.test|1568857236|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Notice: Array to string conversion in Drupal\Core\Render\Markup::create() (line 36 of /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php) #0 /var/www/drupal/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(8, 'Array to string...', '/var/www/drupal...', 36, Array)#012#1 /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php(36): _drupal_error_handler(8, 'Array to string...', '/var/www/drupal...', 36, Array)#012#2 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(753): Drupal\Core\Render\Markup::create(Array)#012#3 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(384): Drupal\Core\Render\Renderer->ensureMarkupIsSafe(Array)#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render(Array)#012#6 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_renderables.html.twig_WMtxrvcEU8n0N-73nZNvN8jKt/V4U04-Z-aq4q_68cUNoEXm2GbjfFnzZCdW6kpd151R4.php(122): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)#012#7 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_field.html.twig_1nF_gLuUjzgK_Z1ARjT-PONS9/QdoSWmziUyyhPPIitWWnoT48OHMOsBW-l-1d9Am9D_M.php(210): __TwigTemplate_a9a17d105d1499cfae9f2eb06d2cb85c3bcd489cd05bfcbd0a2a16a4731aaf59->getmerge_attributes(Object(Drupal\Core\Template\Attribute), Array, 'content')#012#8 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_field.html.twig_1nF_gLuUjzgK_Z1ARjT-PONS9/QdoSWmziUyyhPPIitWWnoT48OHMOsBW-l-1d9Am9D_M.php(88): __TwigTemplate_84f4a8135794fc71b43f28244fc37aee79349b2cb03ee0f60d97fbc38f2671cd->getrender_item(Array, Array, false)#012#9 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_84f4a8135794fc71b43f28244fc37aee79349b2cb03ee0f60d97fbc38f2671cd->doDisplay(Array, Array)#012#10 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#11 /var/www/drupal/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array)#012#12 /var/www/drupal/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render(Array)#012#13 /var/www/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)#012#14 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('field', Array)#012#15 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#16 /var/www/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render(Array)#012#17 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node--findit-program--ful_JAIWVt8GtEvLvjFK9HOD-pDT-/wtcI9mQvF6U9znUdpJqfdXOdW9lFib4xl57rcLqlTWc.php(76): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)#012#18 /var/www/drupal/vendor/twig/twig/src/Template.php(216): __TwigTemplate_44d9812ee70f18d58117fce99a50635d7941eebac20aecaec00cd6299b608db9->block_when_content(Array, Array)#012#19 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node-base--opportunity--f_QvcETz4tqczEpI3hJEK6fh6Fp/MLos6wEWmU3w_4jn693hGYhjFzjBCSJmmsJrVAMaplo.php(213): Twig\Template->displayBlock('when_content', Array, Array)#012#20 /var/www/drupal/vendor/twig/twig/src/Template.php(216): __TwigTemplate_976004d06b2ead812e4dedebed34f1465df49a27146053892be7e9a038c1e90c->block_when(Array, Array)#012#21 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node-base--opportunity--f_QvcETz4tqczEpI3hJEK6fh6Fp/MLos6wEWmU3w_4jn693hGYhjFzjBCSJmmsJrVAMaplo.php(125): Twig\Template->displayBlock('when', Array, Array)#012#22 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_976004d06b2ead812e4dedebed34f1465df49a27146053892be7e9a038c1e90c->doDisplay(Array, Array)#012#23 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#24 /var/www/drupal/web/sites/default/files/php/twig/5d82dc908274b_node--findit-program--ful_JAIWVt8GtEvLvjFK9HOD-pDT-/wtcI9mQvF6U9znUdpJqfdXOdW9lFib4xl57rcLqlTWc.php(60): Twig\Template->display(Array, Array)#012#25 /var/www/drupal/vendor/twig/twig/src/Template.php(455): __TwigTemplate_44d9812ee70f18d58117fce99a50635d7941eebac20aecaec00cd6299b608db9->doDisplay(Array, Array)#012#26 /var/www/drupal/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)#012#27 /var/www/drupal/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array)#012#28 /var/www/drupal/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render(Array)#012#29 /var/www/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)#012#30 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('node', Array)#012#31 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)#012#32 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false)#012#33 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()#012#34 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#35 /var/www/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))#012#36 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))#012#37 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#38 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#39 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))#012#40 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#41 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#42 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#43 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\Htt
Repeat, do not do it this way either, still wrong, keep scrolling.
Making it as dead simple as possible:
if (count($sequence) >= $minimum_sequence) {
$last_element = "First word";
$first_element = "last word";
$connecting_word_markup = "middle word";
$inotherwords[$sequence_id] = [
'#markup' => "@first_element @connecting_word @last_element",
'#attached' => [
'placeholders' => [
'@first_element' => $first_element,
'@connecting_word' => $connecting_word_markup,
'@last_element' => $last_element,
],
],
];
}
// This should work equivalent to the above but retain more flexibility
// for manipulation later, but it fails with errors deep in the render
// system, “strlen() expects parameter 1 to be string, array given” in
// UnicodeValidateUTF8 and Array to string conversion in
// Drupal\Core\Render\Markup::create().
Sep 19 02:15:53 findit-dev drupal: http://findit-dev.test|1568859353|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Warning: Illegal string offset '#create_placeholder' in Drupal\Core\Render\Renderer->renderPlaceholder() (line 163 of /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php) #0 /var/www/drupal/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(2, 'Illegal string ...', '/var/www/drupal...', 163, Array)#012#1 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(163): _drupal_error_handler(2, 'Illegal string ...', '/var/www/drupal...', 163, Array)#012#2 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(667): Drupal\Core\Render\Renderer->renderPlaceholder('@first_element', Array)#012#3 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(552): Drupal\Core\Render\Renderer->replacePlaceholders(Array)#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true)#012#6 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#7 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#8 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(282): Drupal\Core\Render\Renderer->renderRoot(Array)#012#9 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse))#012#10 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))#012#11 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#12 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#13 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent))#012#14 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1)#012#15 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#16 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#17 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#18 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#19 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#20 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#21 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#22 /var/www/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#23 /var/www/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#24 /var/www/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))#012#25 {main}.
Sep 19 02:15:53 findit-dev drupal: http://findit-dev.test|1568859353|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Warning: Cannot assign an empty string to a string offset in Drupal\Core\Render\Renderer->renderPlaceholder() (line 163 of /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php) #0 /var/www/drupal/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(2, 'Cannot assign a...', '/var/www/drupal...', 163, Array)#012#1 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(163): _drupal_error_handler(2, 'Cannot assign a...', '/var/www/drupal...', 163, Array)#012#2 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(667): Drupal\Core\Render\Renderer->renderPlaceholder('@first_element', Array)#012#3 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(552): Drupal\Core\Render\Renderer->replacePlaceholders(Array)#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true)#012#6 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#7 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#8 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(282): Drupal\Core\Render\Renderer->renderRoot(Array)#012#9 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse))#012#10 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))#012#11 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#12 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#13 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent))#012#14 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1)#012#15 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#16 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#17 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#18 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#19 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#20 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#21 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#22 /var/www/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#23 /var/www/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#24 /var/www/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))#012#25 {main}.
Sep 19 02:15:53 findit-dev drupal: http://findit-dev.test|1568859353|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Warning: Illegal string offset '#cache' in Drupal\Core\Render\Renderer->doRender() (line 256 of /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php) #0 /var/www/drupal/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(2, 'Illegal string ...', '/var/www/drupal...', 256, Array)#012#1 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(256): _drupal_error_handler(2, 'Illegal string ...', '/var/www/drupal...', 256, Array)#012#2 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender('last word', true)#012#3 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render('last word', true)#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#6 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain('last word')#012#7 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(667): Drupal\Core\Render\Renderer->renderPlaceholder('@first_element', Array)#012#8 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(552): Drupal\Core\Render\Renderer->replacePlaceholders(Array)#012#9 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)#012#10 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true)#012#11 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#12 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#13 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(282): Drupal\Core\Render\Renderer->renderRoot(Array)#012#14 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse))#012#15 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))#012#16 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#17 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#18 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent))#012#19 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1)#012#20 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#21 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#22 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#23 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#24 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#25 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#26 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#27 /var/www/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#28 /var/www/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#29 /var/www/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))#012#30 {main}.
Sep 19 02:15:53 findit-dev drupal: http://findit-dev.test|1568859353|php|192.168.42.1|http://findit-dev.test/program/new-fall-2019-openings-cambridge-ellis-french-immersion-program|http://findit-dev.test/admin/content?title=&type=findit_program&status=All&langcode=All|1||Error: Cannot use string offset as an array in Drupal\Core\Render\Renderer->doRender() (line 256 of /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php) #0 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender('last word', true)#012#1 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render('last word', true)#012#2 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#3 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#4 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain('last word')#012#5 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(667): Drupal\Core\Render\Renderer->renderPlaceholder('@first_element', Array)#012#6 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(552): Drupal\Core\Render\Renderer->replacePlaceholders(Array)#012#7 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)#012#8 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true)#012#9 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()#012#10 /var/www/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))#012#11 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(282): Drupal\Core\Render\Renderer->renderRoot(Array)#012#12 /var/www/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse))#012#13 /var/www/drupal/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))#012#14 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#15 /var/www/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))#012#16 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent))#012#17 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1)#012#18 /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)#012#19 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#20 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#21 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#22 /var/www/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#23 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#24 /var/www/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#25 /var/www/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#26 /var/www/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)#012#27 /var/www/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))#012#28 {main}.
The bloody documentation was incorrect: https://www.drupal.org/project/drupal/issues/2848367
That is true about the documentation being wrong, but still, just don’t use placeholders as a way of passing in elements. It’s for crazy delayed rendering while everything else is cached.
Load
To simply pass in variables into another render array, do this:
$field_name = $this->fieldDefinition->getLabel();
$field_machine_name = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('label');
$inotherwords[0] = [
'#markup' => new FormattableMarkup($all_items_text, [
'@field_name' => $field_name,
'@field_machine_name' => $field_machine_name,
'@vocabulary_machine_name' => $vocabulary_id,
]),
];
where $all_items_text
can contain the text ‘@field_name’ to be replaced etc.