πŸ‡¬πŸ‡§United Kingdom @simonp98

Account created on 26 February 2013, over 11 years ago
#

Merge Requests

Recent comments

πŸ‡¬πŸ‡§United Kingdom simonp98

Try upgrading Drush to version 12. If Drush won't upgrade remove the exiting Drush and then install version 12. Hope that works!

πŸ‡¬πŸ‡§United Kingdom simonp98

How do I determine if this is actually a spelling error? The logs report the following and this code has previously passed all tests.

/scripts-124688-721749/step_script: line 277: /usr/bin/tr: Argument list too long

/scripts-124688-721749/step_script: line 277: /usr/bin/yarn: Argument list too long

πŸ‡¬πŸ‡§United Kingdom simonp98

simonp98 β†’ made their first commit to this issue’s fork.

πŸ‡¬πŸ‡§United Kingdom simonp98

Improved change record.

πŸ‡¬πŸ‡§United Kingdom simonp98

Added 2 new methods to the MediaLibrarySelectForm class and updated the getValue and viewsForm methods to use the entity mid. See comment #27.

πŸ‡¬πŸ‡§United Kingdom simonp98

simonp98 β†’ changed the visibility of the branch 3388913-10.1.x to hidden.

πŸ‡¬πŸ‡§United Kingdom simonp98

simonp98 β†’ changed the visibility of the branch 3388913-10.1.x to active.

πŸ‡¬πŸ‡§United Kingdom simonp98

The buildForm method of the ViewsFormMainForm class looks for 2 methods on the MediaLibrarySelectForm field that don't exist so defaults to building the placeholders from the row index. The methods appear to be legacy code as the methods are snake case?

The getValue method and the viewsForm method on the MediaLibrarySelectForm field both use the ResultRow $row->index value where I think the $row->mid value might be more appropriate.

Adding the following methods to the MediaLibrarySelectForm class and updating the getValue and viewsForm methods to use the entity mid appears to fix the issue; but I'm not familiar enough with the core code to know if there are further implications in making these changes.

Add new methods to MediaLibrarySelectForm:

  public function form_element_name() {
    return $this->field;
  }

  public function form_element_row_id($row_id) {
    return $this->view->result[$row_id]->mid;
  }

Refactor MediaLibrarySelectForm::getValue to use $row->mid

 public function getValue(ResultRow $row, $field = NULL) {
    return '<!--form-item-' . $this->options['id'] . '--' . $row->mid . '-->';
  }

Refactor MediaLibrarySelectForm::viewsForm to use $row->mid if views field is a media entity

    foreach ($this->view->result as $row_index => $row) {
      $entity = $this->getEntity($row);
      if (!$entity) {
        $form[$this->options['id']][$row_index] = [];
        continue;
      }
      $form[$this->options['id']][$row->mid] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Select @label', [
          '@label' => $entity->label(),
        ]),
        '#title_display' => 'invisible',
        '#return_value' => $entity->id(),
      ];
    }
πŸ‡¬πŸ‡§United Kingdom simonp98

Having this problem with Drupal 10.1.6 and the Media Library widget. Turning off caching for the widget and widget_table in the Media Library view makes the widget usable.

I think the issue is related to caching, lazy building and pagination. Each paged record set in the filter builds the checkbox placeholders in PreRenderViewsForm method of the ViewsFormMainForm class from a 0 index resulting in search array looking like this

array:4 [β–Ό
  0 => "<!--form-item-media_library_select_form--0-->"
  1 => "<!--form-item-media_library_select_form--1-->"
  2 => "<!--form-item-media_library_select_form--2-->"
  3 => "<!--form-item-media_library_select_form--3-->"
]

If Media items are returned from the cache having been on a page where the placeholder key is different then the rendered checkbox will return the wrong media item when selected.

If the placeholder key is beyond the range of the current result, then no substitution takes place and no checkbox is rendered. The following values returned for a 4 media items result in only one checkbox being rendered (the one with the key of 3).

<!--form-item-media_library_select_form--3-->
<!--form-item-media_library_select_form--4-->
<!--form-item-media_library_select_form--5-->
<!--form-item-media_library_select_form--7-->

Hopefully this gives a bit more insight into the issue.

Production build 0.69.0 2024