Verified Commit 0b863641 authored by Jess's avatar Jess
Browse files

Issue #2939442 by Lendude, jidrone, joachim, Akhil Babu, Kristen Pol,...

Issue #2939442 by Lendude, jidrone, joachim, Akhil Babu, Kristen Pol, larowlan: Views 'Entity Operations' field crashes if on a non-required relationship
parent 0b548bb6
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -127,7 +127,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $entity = $this->getEntityTranslation($this->getEntity($values), $values);
    $entity = $this->getEntity($values);
    // Allow for the case where there is no entity, if we are on a non-required
    // relationship.
    if (empty($entity)) {
      return '';
    }
    $entity = $this->getEntityTranslation($entity, $values);
    $operations = $this->entityTypeManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);
    if ($this->options['destination']) {
      foreach ($operations as &$operation) {
+14 −0
Original line number Diff line number Diff line
@@ -174,4 +174,18 @@ public function testRenderWithoutDestination() {
    $this->assertSame($expected_build, $build);
  }

  /**
   * @covers ::render
   */
  public function testRenderWithoutEntity() {
    $entity = NULL;

    $result = new ResultRow();
    $result->_entity = $entity;

    $expected_build = '';
    $build = $this->plugin->render($result);
    $this->assertSame($expected_build, $build);
  }

}