Skip to content
Snippets Groups Projects
Verified Commit 56c078e5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3440041 by quietone, mondrake: Log warning for an invalid view display...

Issue #3440041 by quietone, mondrake: Log warning for an invalid view display in  \Drupal\views\ViewExecutable::setDisplay
parent e7ec8284
No related branches found
No related tags found
28 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #148293 canceled
Pipeline: drupal

#148298

    ......@@ -2,9 +2,9 @@
    namespace Drupal\views;
    use Drupal\Component\Render\FormattableMarkup;
    use Drupal\Component\Utility\Html;
    use Drupal\Component\Utility\Tags;
    use Drupal\Core\Logger\LoggerChannelTrait;
    use Drupal\Core\Routing\RouteProviderInterface;
    use Drupal\Core\Session\AccountInterface;
    use Drupal\views\Plugin\views\display\DisplayRouterInterface;
    ......@@ -28,6 +28,8 @@
    #[\AllowDynamicProperties]
    class ViewExecutable {
    use LoggerChannelTrait;
    /**
    * The config entity in which the view is stored.
    *
    ......@@ -821,7 +823,12 @@ public function setDisplay($display_id = NULL) {
    // Ensure the requested display exists.
    if (!$this->displayHandlers->has($display_id)) {
    trigger_error(new FormattableMarkup('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id]), E_USER_WARNING);
    $this->getLogger('views')->warning(
    'setDisplay() called with invalid display ID "@display_id".',
    [
    '@display_id' => $display_id,
    ],
    );
    return FALSE;
    }
    ......
    ......@@ -6,6 +6,7 @@
    use Drupal\comment\Tests\CommentTestTrait;
    use Drupal\Component\Utility\Xss;
    use Drupal\Core\Database\Database;
    use Drupal\node\Entity\NodeType;
    use Drupal\views\Entity\View;
    use Drupal\views\Views;
    ......@@ -21,7 +22,6 @@
    use Drupal\views\Plugin\views\pager\PagerPluginBase;
    use Drupal\views\Plugin\views\query\QueryPluginBase;
    use Drupal\views_test_data\Plugin\views\display\DisplayTest;
    use PHPUnit\Framework\Error\Warning;
    use Symfony\Component\HttpFoundation\Response;
    /**
    ......@@ -204,17 +204,22 @@ public function testProperties() {
    }
    public function testSetDisplayWithInvalidDisplay() {
    \Drupal::service('module_installer')->install(['dblog']);
    $view = Views::getView('test_executable_displays');
    $view->initDisplay();
    // Error is triggered while calling the wrong display.
    try {
    $view->setDisplay('invalid');
    $this->fail('Expected error, when setDisplay() called with invalid display ID');
    }
    catch (Warning $e) {
    $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage());
    }
    // Error is logged while calling the wrong display.
    $view->setDisplay('invalid');
    $arguments = [
    '@display_id' => 'invalid',
    ];
    $logged = Database::getConnection()->select('watchdog')
    ->fields('watchdog', ['variables'])
    ->condition('type', 'views')
    ->condition('message', 'setDisplay() called with invalid display ID "@display_id".')
    ->execute()
    ->fetchField();
    $this->assertEquals(serialize($arguments), $logged);
    $this->assertEquals('default', $view->current_display, 'If setDisplay is called with an invalid display id the default display should be used.');
    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->display_handler));
    ......
    ......@@ -4,6 +4,7 @@
    namespace Drupal\Tests\views_ui\Functional;
    use Drupal\Core\Database\Database;
    use Drupal\language\Entity\ConfigurableLanguage;
    use Drupal\views\Entity\View;
    ......@@ -50,6 +51,7 @@ public function testDeleteLink() {
    * Tests the machine name and administrative comment forms.
    */
    public function testOtherOptions() {
    \Drupal::service('module_installer')->install(['dblog']);
    $this->drupalGet('admin/structure/views/view/test_view');
    // Add a new attachment display.
    $this->submitForm([], 'Add Attachment');
    ......@@ -85,13 +87,17 @@ public function testOtherOptions() {
    $error_text = 'Display machine name must contain only lowercase letters, numbers, or underscores.';
    // Test that potential invalid display ID requests are detected
    try {
    $this->drupalGet('admin/structure/views/ajax/handler/test_view/fake_display_name/filter/title');
    $this->fail('Expected error, when setDisplay() called with invalid display ID');
    }
    catch (\Exception $e) {
    $this->assertStringContainsString('setDisplay() called with invalid display ID "fake_display_name".', $e->getMessage());
    }
    $this->drupalGet('admin/structure/views/ajax/handler/test_view/fake_display_name/filter/title');
    $arguments = [
    '@display_id' => 'fake_display_name',
    ];
    $logged = Database::getConnection()->select('watchdog')
    ->fields('watchdog', ['variables'])
    ->condition('type', 'views')
    ->condition('message', 'setDisplay() called with invalid display ID "@display_id".')
    ->execute()
    ->fetchField();
    $this->assertEquals(serialize($arguments), $logged);
    $edit = ['display_id' => 'test 1'];
    $this->drupalGet($machine_name_edit_url);
    ......
    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