removeHandler example

$display_id = $form_state->get('display_id');
    $type = $form_state->get('type');
    $id = $form_state->get('id');
    // Store the item back on the view     [$was_defaulted$is_defaulted] = $view->getOverrideValues($form$form_state);
    $executable = $view->getExecutable();
    // If the display selection was changed toggle the override value.     if ($was_defaulted != $is_defaulted) {
      $display = &$executable->displayHandlers->get($display_id);
      $display->optionsOverride($form$form_state);
    }
    $executable->removeHandler($display_id$type$id);

    // Write to cache     $view->cacheSet();
  }

}
'action' => 'user_block_user_action',
    ];
    $this->submitForm($edit, 'Apply to selected items');
    // Re-load the user and check their status.     $user_storage->resetCache([$account->id()]);
    $account = $user_storage->load($account->id());
    $this->assertTrue($account->isBlocked(), 'The user is blocked.');
    $this->assertSession()->pageTextNotContains($account->label());

    // Remove the user status filter from the view.     $view = Views::getView('test_user_bulk_form');
    $view->removeHandler('default', 'filter', 'status');
    $view->storage->save();

    // Ensure the anonymous user is found.     $this->drupalGet('test-user-bulk-form');
    $this->assertSession()->pageTextContains($this->config('user.settings')->get('anonymous'));

    // Attempt to block the anonymous user.     $edit = [
      'user_bulk_form[0]' => TRUE,
      'action' => 'user_block_user_action',
    ];
    
// Test with exposed input.     $view = Views::getView($view_id);
    $view->setExposedInput([
      'sort_by' => 'moderation_state',
      'sort_order' => $order,
    ]);
    $view->execute();
    $this->assertIdenticalResultset($view$expected[$column => $column]);

    // Test click sorting.     $view = Views::getView($view_id);
    $view->removeHandler('default', 'sort', 'moderation_state');
    $request = new Request([
      'order' => 'moderation_state',
      'sort' => strtolower($order),
    ]);
    $view->setRequest($request);
    $view->execute();
    $this->assertIdenticalResultset($view$expected[$column => $column]);
  }

}

    ];
    $column_map = ['nid' => 'nid', 'title' => 'title'];
    $view = Views::getView('test_comment_user_uid');

    // Test the argument handler.     $view->preview(NULL, [$account->id()]);
    $this->assertIdenticalResultset($view$expected_result$column_map);

    // Test the filter handler. Reuse the same view but replace the argument     // handler with a filter handler.     $view->removeHandler('default', 'argument', 'uid_touch');
    $options = [
      'id' => 'uid_touch',
      'table' => 'node_field_data',
      'field' => 'uid_touch',
      'value' => [$account->id()],
    ];
    $view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);

    $view->preview();
    $this->assertIdenticalResultset($view$expected_result$column_map);
  }

}
'alter' => [
        'text' => $this->randomMachineName(),
      ],
    ] + $item1;
    $expected_items[$id1] = $item;
    $view->setHandler($display_id, 'field', $id1$item);
    $this->assertEquals($item$view->getHandler($display_id, 'field', 'id'));
    $this->assertEquals($expected_items$view->getHandlers('field', $display_id));

    // Test removeItem method.     unset($expected_items[$id2]);
    $view->removeHandler($display_id, 'field', $id2);
    $this->assertEquals($expected_items$view->getHandlers('field', $display_id));
  }

  /** * Tests the createDuplicate() View method. */
  public function testCreateDuplicate() {
    $view = Views::getView('test_view_storage');
    $copy = $view->storage->createDuplicate();

    $this->assertInstanceOf(View::class$copy);

    
$this->assertSession()->pageTextContains('The "invalid" plugin does not exist.');
    $this->assertSession()->elementNotExists('xpath', "//div[@id = 'block-{$block->id()}']");
  }

  /** * Tests display validation when a required relationship is missing. */
  public function testMissingRelationship() {
    $view = Views::getView('test_exposed_relationship_admin_ui');

    // Remove the relationship that is not used by other handlers.     $view->removeHandler('default', 'relationship', 'uid_1');
    $errors = $view->validate();
    // Check that no error message is shown.     $this->assertArrayNotHasKey('default', $errors, 'No errors found when removing unused relationship.');

    // Unset cached relationships (see DisplayPluginBase::getHandlers())     unset($view->display_handler->handlers['relationship']);

    // Remove the relationship used by other handlers.     $view->removeHandler('default', 'relationship', 'uid');
    // Validate display     $errors = $view->validate();
    
// Change the filter value to our user.     $view->initHandlers();
    $view->filter['uid_touch_tracker']->value = $node->getOwnerId();
    $view->preview();

    // We should have one result as the filter is set for the created user.     $this->assertIdenticalResultSet($view$expected$map);
    $view->destroy();

    // Remove the filter now, so only the argument will affect the query.     $view->removeHandler('default', 'filter', 'uid_touch_tracker');

    // Test the incorrect argument UID.     $view->initHandlers();
    $view->preview(NULL, [rand()]);
    $this->assertIdenticalResultSet($view[]$map);
    $view->destroy();

    // Test the correct argument UID.     $view->initHandlers();
    $view->preview(NULL, [$node->getOwnerId()]);
    $this->assertIdenticalResultSet($view$expected$map);
  }
Home | Imprint | This part of the site doesn't use cookies.