Skip to content
Snippets Groups Projects
Commit c92948d6 authored by Xaq Rothman's avatar Xaq Rothman Committed by Eirik Morland
Browse files

Issue #3186322 by eiriksm, JeroenT: 'All' options in...

Issue #3186322 by eiriksm, JeroenT: 'All' options in hook_form_views_exposed_form_alter cause error when code or result filters are removed
parent b54e359d
No related branches found
No related tags found
No related merge requests found
...@@ -103,3 +103,10 @@ field.field.*.*.*.third_party.linkchecker: ...@@ -103,3 +103,10 @@ field.field.*.*.*.third_party.linkchecker:
extractor: extractor:
type: string type: string
label: 'Extractor plugin machine name' label: 'Extractor plugin machine name'
views.field.linkcheckerlink_page_entity_label:
type: views.field.field
mapping:
link_to_entity:
type: integer
label: 'Link to entity.'
...@@ -197,12 +197,19 @@ function linkchecker_entity_delete(EntityInterface $entity) { ...@@ -197,12 +197,19 @@ function linkchecker_entity_delete(EntityInterface $entity) {
* Implements hook_form_BASE_FORM_ID_alter(). * Implements hook_form_BASE_FORM_ID_alter().
*/ */
function linkchecker_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) { function linkchecker_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form['#id'] == 'views-exposed-form-broken-links-report-page-1') { if ($form['#id'] != 'views-exposed-form-broken-links-report-page-1') {
return;
}
if (!empty($form['result'])) {
$form['result']['#states'] = [ $form['result']['#states'] = [
'enabled' => [ 'enabled' => [
':input[name="code"]' => ['value' => ''], ':input[name="code"]' => ['value' => ''],
], ],
]; ];
}
if (!empty($form['code'])) {
$form['code']['#states'] = [ $form['code']['#states'] = [
'enabled' => [ 'enabled' => [
'select[name="result"]' => ['value' => 'All'], 'select[name="result"]' => ['value' => 'All'],
......
<?php
namespace Drupal\Tests\linkchecker\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Test Link checker overview view.
*
* @group linkchecker
*/
class LinkCheckerOverviewTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'filter',
'content_translation',
'linkchecker',
'node',
'path',
'views',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser([
'administer linkchecker',
'bypass node access',
'access broken links report',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Test that we can go to the overview and see our URLs there.
*
* Also tests that our states functionality works and does not trigger any PHP
* notices.
*/
public function testOverviewWorks() {
// Remove the result exposed filter.
/** @var \Drupal\Core\Config\ImmutableConfig $view_config */
$view_config = $this->container->get('config.factory')->getEditable('views.view.broken_links_report');
// Now visit the view of broken links.
$route = 'view.broken_links_report.page_1';
$this->drupalGet(Url::fromRoute($route)->toString());
self::assertEquals(200, $this->getSession()->getStatusCode());
$data = $view_config->getRawData();
foreach (['code', 'code_1'] as $field) {
unset($data["display"]["default"]["display_options"]["filters"][$field]);
}
$view_config->setData($data);
$view_config->save();
$this->drupalGet(Url::fromRoute($route)->toString());
self::assertEquals(200, $this->getSession()->getStatusCode());
}
}
<?php
namespace Drupal\Tests\linkchecker\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Test Link checker overview view.
*
* @group linkchecker
*/
class LinkCheckerOverviewTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'filter',
'content_translation',
'linkchecker',
'node',
'path',
'views',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser([
'administer linkchecker',
'bypass node access',
'access broken links report',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Test that we can go to the overview and see our URLs there.
*
* Also tests that our states functionality works and does not trigger any PHP
* notices.
*/
public function testOverviewWorks() {
// Remove the result exposed filter.
/** @var \Drupal\Core\Config\ImmutableConfig $view_config */
$view_config = $this->container->get('config.factory')->getEditable('views.view.broken_links_report');
// Now visit the view of broken links.
$route = 'view.broken_links_report.page_1';
$this->drupalGet(Url::fromRoute($route)->toString());
// Check that the states part does what it is supposed to do.
// Unset a couple of things that used to end up triggering an undefined
// index.
$page = $this->getSession()->getPage();
$page->fillField('result', '2');
self::assertTrue($page->find('css', '[data-drupal-selector="edit-code"]')->hasAttribute('disabled'));
$page->fillField('result', 'All');
self::assertFalse($page->find('css', '[data-drupal-selector="edit-code"]')->hasAttribute('disabled'));
$page->fillField('code', '200');
self::assertTrue($page->find('css', '[data-drupal-selector="edit-result"]')->hasAttribute('disabled'));
$page->fillField('code', '');
self::assertFalse($page->find('css', '[data-drupal-selector="edit-result"]')->hasAttribute('disabled'));
$data = $view_config->getRawData();
foreach (['code', 'code_1'] as $field) {
unset($data["display"]["default"]["display_options"]["filters"][$field]);
}
$view_config->setData($data);
$view_config->save();
$this->drupalGet(Url::fromRoute($route)->toString());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment