Error on adding media entity browser [closed]

I’ve added some paragraph in my content type. In a paragraph, I’ve added another paragraph with some data, including a media inside another content type

When I’m trying to add a media, I have this in my console :

DrupalCoreRenderElement::children() must be of the type array, null
given modules/contrib/entity_browser/entity_browser.module

Caused by the foreach part. First, I simply tried to add a condition around the foreach to see if ton only.

foreach (Element::children($form['actions']) != null

After, I had an error on the getEntity() on null . What can I do has a patch to fix it without breaking the entity_browser ? Knowing that entity_browser works fine when I edit the media

function entity_browser_form_alter(&$form, FormStateInterface &$form_state) {
  $entity_browser_dialog_edit = Drupal::service('request_stack')->getCurrentRequest()->get('_route');
  if ($entity_browser_dialog_edit == 'entity_browser.edit_form') {
    // Let's allow the save button only.
    foreach (Element::children($form['actions']) as $key) {
      $form['actions'][$key]['#access'] = $key == 'submit';
    }
    // Use Ajax.
    $form['actions']['submit']['#ajax'] = [
      'url' => Url::fromRoute('entity_browser.edit_form', ['entity_type' => $form_state->getFormObject()->getEntity()->getEntityTypeId(), 'entity' => $form_state->getFormObject()->getEntity()->id()]),
      'options' => [
        'query' => [
          'details_id' => Drupal::request()->query->get('details_id'),
        ],
      ],
      'disable-refocus' => TRUE,
    ];
  }
}

This is basicaly my structure :

| - Page
  | ---- Paragraph
    | - Slider
      | - Slide
        | - Content type
           | - Media
      | - Slide
        | - Content type
           | - Media
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Error on adding media entity browser [closed]

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.