UserBulkForm.php

Same filename in other branches
  1. 9 core/modules/user/src/Plugin/views/field/UserBulkForm.php
  2. 8.9.x core/modules/user/src/Plugin/views/field/UserBulkForm.php
  3. 11.x core/modules/user/src/Plugin/views/field/UserBulkForm.php

Namespace

Drupal\user\Plugin\views\field

File

core/modules/user/src/Plugin/views/field/UserBulkForm.php

View source
<?php

namespace Drupal\user\Plugin\views\field;

use Drupal\Core\Form\FormStateInterface;
use Drupal\user\UserInterface;
use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\BulkForm;

/**
 * Defines a user operations bulk form element.
 */
class UserBulkForm extends BulkForm {
    
    /**
     * {@inheritdoc}
     *
     * Provide a more useful title to improve the accessibility.
     */
    public function viewsForm(&$form, FormStateInterface $form_state) {
        parent::viewsForm($form, $form_state);
        if (!empty($this->view->result)) {
            foreach ($this->view->result as $row_index => $result) {
                $account = $result->_entity;
                if ($account instanceof UserInterface) {
                    $form[$this->options['id']][$row_index]['#title'] = $this->t('Update the user %name', [
                        '%name' => $account->label(),
                    ]);
                }
            }
        }
    }
    
    /**
     * {@inheritdoc}
     */
    protected function emptySelectedMessage() {
        return $this->t('No users selected.');
    }

}

Classes

Title Deprecated Summary
UserBulkForm Defines a user operations bulk form element.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.