Is there a way to configure the entity browser bulk select form (views) to have a select all checkbox? My idea is that I would use several exposed filters to narrow down the results and then click "select all."

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Adrian83 created an issue. See original summary.

adrian83’s picture

Here is the answer I got from Mohammed Razem on Varbase Slack:

@Adrian83 this is an interesting feature. I think the best way is to patch the enhancer on Entity Browser Enhanced. Since this is the module that enhances the “javascript” select for Entity Browsers. typically this is where you will be patching http://cgit.drupalcode.org/entity_browser_enhanced/tree/enhancers/multiselect/js/entity_browser_enhanced.multiselect.js?h=8.x-1.x

hardik_patel_12’s picture

Assigned: Unassigned » hardik_patel_12
hardik_patel_12’s picture

please check this patch

hardik_patel_12’s picture

Status: Active » Needs review
hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
snehalgaikwad’s picture

Assigned: Unassigned » snehalgaikwad
snehalgaikwad’s picture

Status: Needs review » Needs work

"select all" checkbox is appearing only if there is
i.e. if label for any of the field is visible. Either User has to make sure label is always present or changes need to be made in code to add default header. Also checkboxed are checked on class

tbody .views-field-entity-browser-select input.form-checkbox

which is not for any particular entity browser field. It should be like getting the parent element of select all checkbox and then add checked property to children.

hardik_patel_12’s picture

StatusFileSize
new965 bytes

@snehalgaikwad now select all checkbox is independent of field label.

hardik_patel_12’s picture

Status: Needs work » Needs review
snehalgaikwad’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the fixes @Hardik_Patel_12. I have tested patch and it is working fine.

hardik_patel_12’s picture

Assigned: snehalgaikwad » Unassigned
danharper’s picture

I've tried to test this patch and it seems to be working ok

Thanks Dan

anybody’s picture

Well it works but is this really the perfect implementation?

#2842313: Missing tableselect dependency in view seems duplicate and the better Drupal-way implementation?

anybody’s picture

Status: Reviewed & tested by the community » Needs review
MoumitaK’s picture

I use this patch in entity browser view.. But when I am going to the network to check, the .js file is not displaying over there. Can anyone let me know there is any other way for that?

prografr’s picture

#9 worked for me thnx @Hardik_Patel_12
hope to merge this handy feature..

kt2ssh’s picture

I want the "select all options across all pages" (assumed pager is set) feature just like what VBO does but I can't find any solution from entity browser or entity browser enhanced modules.
now I end up with this snippet below, but it only work for views widget and node type specifically.

function modulename_entity_browser_select_all($form, &$form_state) {
  $values = $form_state->getUserInput();
  $trigger = $form_state->getTriggeringElement();
  $select_all = empty($trigger['#attributes']['data-select-all']) ? false : true;
  if ($select_all) {
    $filters = [];
    foreach ($values as $k => $v) {
      if (substr($k, 0, 6) == 'field_') {
        $filters[$k] = $v;
      }
    }
    $conf = $form_state->getFormObject()->getEntityBrowser()->getWidgets()->getConfiguration();
    $wid = $form_state->get('entity_browser_current_widget');
    $setting = $conf[$wid]['settings'];
    $view = \Drupal\views\Views::getView($setting['view']);
    if (is_object($view)) {
      $view->setArguments($setting['views_arguments']);
      $view->setDisplay($setting['view_display']);
      $view->setItemsPerPage(100000000);
      $view->setExposedInput($filters);
      $view->preExecute();
      $view->execute();
      foreach ($view->result as $row) {
        $nid = $row->nid;
        $values['entity_browser_select']['node:' . $nid] = 'node:' . $nid;
      }
      $form_state->setUserInput($values);
    }
  }
}

/**
 * Implements hook_form_alter().
 */
function modulename_form_alter(&$form, &$form_state, $form_id) {
  if (substr($form_id, 0, 15) == 'entity_browser_') {
    $entitybrowser = $form_state->getFormObject()->getEntityBrowser();
    $form['#submit'] = array_merge(['modulename_entity_browser_select_all'], $form['#submit']);
    $form['widget']['actions']['select_all'] = $form['widget']['actions']['submit'];
    $form['widget']['actions']['select_all']['#value'] = 'Add All Items';
    $form['widget']['actions']['select_all']['#attributes']['data-select-all'] = 1;
  }
}
rogeriocc’s picture

# 9 stopped work on Entity Browser 2.6 and Drupal 9.2.7

acbramley made their first commit to this issue’s fork.

acbramley’s picture

Title: How to create a "select all" checkbox with views bulk select form » Add a "select all" checkbox with views bulk select form
Category: Support request » Feature request

Code in MR20 still worked, although it was on the 8.x-2.x branch which causes issues when cloning.

Rebased HEAD on to 2922313-how-to-create, cherry-picked the JS and made some changes to the select all markup.

danharper’s picture

I'm using MR30 and it's working on 2.x-dev can this be marked as reviewed & tested?

acbramley changed the visibility of the branch 8.x-2.x to hidden.