コード例 #1
0
 /**
  * Tests the constructor assignment of actions.
  */
 public function testConstructor()
 {
     $actions = array();
     for ($i = 1; $i <= 2; $i++) {
         $action = $this->getMock('\\Drupal\\system\\ActionConfigEntityInterface');
         $action->expects($this->any())->method('getType')->will($this->returnValue('user'));
         $actions[$i] = $action;
     }
     $action = $this->getMock('\\Drupal\\system\\ActionConfigEntityInterface');
     $action->expects($this->any())->method('getType')->will($this->returnValue('node'));
     $actions[] = $action;
     $entity_storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $entity_storage->expects($this->any())->method('loadMultiple')->will($this->returnValue($actions));
     $views_data = $this->getMockBuilder('Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock();
     $views_data->expects($this->any())->method('get')->with('users')->will($this->returnValue(array('table' => array('entity type' => 'user'))));
     $container = new ContainerBuilder();
     $container->set('views.views_data', $views_data);
     \Drupal::setContainer($container);
     $storage = $this->getMock('Drupal\\views\\ViewStorageInterface');
     $storage->expects($this->any())->method('get')->with('base_table')->will($this->returnValue('users'));
     $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock();
     $executable->storage = $storage;
     $display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock();
     $definition['title'] = '';
     $options = array();
     $user_bulk_form = new UserBulkForm(array(), 'user_bulk_form', $definition, $entity_storage);
     $user_bulk_form->init($executable, $display, $options);
     $this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $user_bulk_form);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     if (roleassign_restrict_access()) {
         // Remove actions that are not allowed based on RoleAssign settings.
         $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles'));
         foreach ($this->actions as $action_key => $action) {
             if (in_array($action->get('plugin'), array('user_add_role_action', 'user_remove_role_action'))) {
                 $config = $action->get('configuration');
                 if (!in_array($config['rid'], $assignable_roles)) {
                     unset($this->actions[$action_key]);
                 }
             }
         }
     }
 }