Score:0

Render custom region into node twig template

jp flag

My code used for D8 doesn't work anymore for D9. Custom region twig template for region into node twig template

I get thise error and WSOD:

Error : Call to undefined function entity_load_multiple_by_properties() dans themex_add_regions_to_node() (/home/xx/www/pfdev/multid9/recommended-project/web/themes/custom/themex/themex.theme ligne 145)

I notice that the condition on the region doesn't work too but I can render the content region with twig tweak syntax (outside the if condition):

{% if region_Zone_1 is not empty %}
  <div {{ noderegion_attribute.addClass(noderegion_classes).setAttribute('id', 'region-zone-1') }}>
    {{ region_Zone_1 }}
    {# Avec le module twig_tweak #}
    {{ drupal_region('region_Zone_1') }}
  </div>
  <!-- /#region-zone_1 -->
{% endif %}

So, what's the way to do the same thing or fix it for D9 ?

Thanks

EDIT: is this could fix my issue ? $blocks = entity_load_multiple_by_properties('block', array('theme' => $theme, 'region' => $region)); replaced by:

$blocks = \Drupal::entityTypeManager()
        ->getStorage('block')
        ->loadByProperties(['theme' => $theme, 'region' => $region)]);
Kevin avatar
in flag
That function was deprecated and removed in D9: https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_load_multiple_by_properties/8.5.x
WebmasterPF avatar
jp flag
Thanks. So what I need to modify in my code or what the way to use regions into node template ?
Score:0
id flag

here you have example, how it was patched in contrib module:

diff --git a/modules/webform_submission_export_import   /webform_submission_export_import.module b/modules/webform_submission_export_import/webform_submission_export_import.module    
index 69267d2a5..fd4e8b4ba 100644
--- a/modules/webform_submission_export_import/webform_submission_export_import.module
+++ b/modules/webform_submission_export_import/webform_submission_export_import.module
@@ -236,7 +236,9 @@ function _webform_submission_export_import_file_save_upload_single(\SplFileInfo
   // @todo Do not create a new entity in order to update it. See
   //   https://www.drupal.org/node/2241865.
   if ($replace == FileSystemInterface::EXISTS_REPLACE) {
-    $existing_files = entity_load_multiple_by_properties('file', ['uri' => $file->getFileUri()]);
+    $existing_files = \Drupal::entityTypeManager()
+      ->getStorage('file')
+      ->loadByProperties(['uri' => $file->getFileUri()]);
     if (count($existing_files)) {
       $existing = reset($existing_files);
       $file->fid = $existing->id();

Also there are helpful modules that takes care of this kinds of problems by creating patches or even changing the code automatically (you should use them on your D8 version of website). I used them to switch to D9 and it saved me a lot of time:

WebmasterPF avatar
jp flag
thanks . I figure it out with your code and brain juice ;)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.