Commit e7f64175 authored by catch's avatar catch
Browse files

Issue #2796045 by Lendude, abarrio, ranjith_kumar_k_u, megan_m, joachim,...

Issue #2796045 by Lendude, abarrio, ranjith_kumar_k_u, megan_m, joachim, alexpott, estoyausente, larowlan: Adding a field with relationship results in confusing error message when relationship is not present

(cherry picked from commit 5d4b11b2)
parent 356e9e17
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -2532,7 +2532,12 @@ public function validate() {
    foreach (ViewExecutable::getHandlerTypes() as $type => $handler_type_info) {
      foreach ($this->getHandlers($type) as $handler) {
        if (!empty($handler->options['relationship']) && $handler->options['relationship'] != 'none' && !in_array($handler->options['relationship'], $relationships)) {
          $errors[] = $this->t('The %handler_type %handler uses a relationship that has been removed.', ['%handler_type' => $handler_type_info['lstitle'], '%handler' => $handler->adminLabel()]);
          $errors[] = $this->t('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', [
            '%relationship_name' => $handler->options['relationship'],
            '%handler_type' => $handler_type_info['lstitle'],
            '%handler' => $handler->adminLabel(),
            '%display_name' => $this->display['display_title'],
          ]);
        }
      }
    }
+3 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\views\Functional\Plugin;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views;
@@ -362,8 +363,8 @@ public function testMissingRelationship() {
    $errors = $view->validate();
    // Check that the error messages are shown.
    $this->assertCount(2, $errors['default'], 'Error messages found for required relationship');
    $this->assertEquals(t('The %handler_type %handler uses a relationship that has been removed.', ['%handler_type' => 'field', '%handler' => 'User: Last login']), $errors['default'][0]);
    $this->assertEquals(t('The %handler_type %handler uses a relationship that has been removed.', ['%handler_type' => 'field', '%handler' => 'User: Created']), $errors['default'][1]);
    $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Last login', '%display_name' => 'Default']), $errors['default'][0]);
    $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Created', '%display_name' => 'Default']), $errors['default'][1]);
  }

  /**