outputIsEmpty example

$settings['items_per_page'] = 'none';
    return $settings;
  }

  /** * The display block handler returns the structure necessary for a block. */
  public function execute() {
    // Prior to this being called, the $view should already be set to this     // display, and arguments should be set on the view.     $element = $this->view->render();
    if ($this->outputIsEmpty() && $this->getOption('block_hide_empty') && empty($this->view->style_plugin->definition['even empty'])) {
      return [];
    }
    else {
      return $element;
    }
  }

  /** * Provide the summary for page options in the views UI. * * This output is returned as an array. */
      $search = "$view_name:$display_id";
      if (in_array($search$this->view->parent_views)) {
        \Drupal::messenger()->addError($this->t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id]));
      }
      else {
        if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
          $output = $view->preview($display_id$this->view->args);
        }
        else {
          $output = $view->preview($display_id);
        }
        $this->isEmpty = $view->display_handler->outputIsEmpty();
        return $output;
      }
    }
    return [];
  }

  /** * {@inheritdoc} */
  public function isEmpty() {
    if (isset($this->isEmpty)) {
      
$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]);
  }

  /** * Tests the outputIsEmpty method on the display. */
  public function testOutputIsEmpty() {
    $view = Views::getView('test_display_empty');
    $this->executeView($view);
    $this->assertNotEmpty($view->result);
    $this->assertFalse($view->display_handler->outputIsEmpty(), 'Ensure the view output is marked as not empty.');
    $view->destroy();

    // Add a filter, so the view result is empty.     $view->setDisplay('default');
    $item = [
      'table' => 'views_test_data',
      'field' => 'id',
      'id' => 'id',
      'value' => ['value' => 7297],
    ];
    $view->setHandler('default', 'filter', 'id', $item);
    
Home | Imprint | This part of the site doesn't use cookies.