0

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)]);
2

1 Answer 1

0

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:

1
  • thanks . I figure it out with your code and brain juice ;) Feb 10 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.