You are here

class TraceableViewExecutable in Devel 8.2

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Views/TraceableViewExecutable.php \Drupal\webprofiler\Views\TraceableViewExecutable
  2. 8 webprofiler/src/Views/TraceableViewExecutable.php \Drupal\webprofiler\Views\TraceableViewExecutable
  3. 4.x webprofiler/src/Views/TraceableViewExecutable.php \Drupal\webprofiler\Views\TraceableViewExecutable

Class TraceableViewExecutable

Hierarchy

Expanded class hierarchy of TraceableViewExecutable

1 file declares its use of TraceableViewExecutable
ViewsDataCollector.php in webprofiler/src/DataCollector/ViewsDataCollector.php

File

webprofiler/src/Views/TraceableViewExecutable.php, line 12

Namespace

Drupal\webprofiler\Views
View source
class TraceableViewExecutable extends ViewExecutable {

  /**
   * @var float
   */
  protected $render_time;

  /**
   * Gets the build time.
   *
   * @return float
   */
  public function getBuildTime() {
    return $this->build_time;
  }

  /**
   * Gets the execute time.
   *
   * @return float
   */
  public function getExecuteTime() {
    return property_exists($this, 'execute_time') ? $this->execute_time : 0.0;
  }

  /**
   * Gets the render time.
   *
   * @return float
   */
  public function getRenderTime() {
    return $this->render_time;
  }

  /**
   * {@inheritdoc}
   */
  public function render($display_id = NULL) {
    $start = microtime(TRUE);
    $this
      ->execute($display_id);

    // Check to see if the build failed.
    if (!empty($this->build_info['fail'])) {
      return;
    }
    if (!empty($this->build_info['denied'])) {
      return;
    }

    /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
    $exposed_form = $this->display_handler
      ->getPlugin('exposed_form');
    $exposed_form
      ->preRender($this->result);
    $module_handler = \Drupal::moduleHandler();

    // @TODO In the longrun, it would be great to execute a view without
    //   the theme system at all. See https://www.drupal.org/node/2322623.
    $active_theme = \Drupal::theme()
      ->getActiveTheme();
    $themes = array_keys($active_theme
      ->getBaseThemes());
    $themes[] = $active_theme
      ->getName();

    // Check for already-cached output.

    /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
    if (!empty($this->live_preview)) {
      $cache = Views::pluginManager('cache')
        ->createInstance('none');
    }
    else {
      $cache = $this->display_handler
        ->getPlugin('cache');
    }

    // Run preRender for the pager as it might change the result.
    if (!empty($this->pager)) {
      $this->pager
        ->preRender($this->result);
    }

    // Initialize the style plugin.
    $this
      ->initStyle();
    if (!isset($this->response)) {

      // Set the response so other parts can alter it.
      $this->response = new Response('', 200);
    }

    // Give field handlers the opportunity to perform additional queries
    // using the entire resultset prior to rendering.
    if ($this->style_plugin
      ->usesFields()) {
      foreach ($this->field as $id => $handler) {
        if (!empty($this->field[$id])) {
          $this->field[$id]
            ->preRender($this->result);
        }
      }
    }
    $this->style_plugin
      ->preRender($this->result);

    // Let each area handler have access to the result set.
    $areas = [
      'header',
      'footer',
    ];

    // Only call preRender() on the empty handlers if the result is empty.
    if (empty($this->result)) {
      $areas[] = 'empty';
    }
    foreach ($areas as $area) {
      foreach ($this->{$area} as $handler) {
        $handler
          ->preRender($this->result);
      }
    }

    // Let modules modify the view just prior to rendering it.
    $module_handler
      ->invokeAll('views_pre_render', [
      $this,
    ]);

    // Let the themes play too, because pre render is a very themey thing.
    foreach ($themes as $theme_name) {
      $function = $theme_name . '_views_pre_render';
      if (function_exists($function)) {
        $function($this);
      }
    }
    $this->display_handler->output = $this->display_handler
      ->render();
    $exposed_form
      ->postRender($this->display_handler->output);
    $cache
      ->postRender($this->display_handler->output);

    // Let modules modify the view output after it is rendered.
    $module_handler
      ->invokeAll('views_post_render', [
      $this,
      &$this->display_handler->output,
      $cache,
    ]);

    // Let the themes play too, because post render is a very themey thing.
    foreach ($themes as $theme_name) {
      $function = $theme_name . '_views_post_render';
      if (function_exists($function)) {
        $function($this, $this->display_handler->output, $cache);
      }
    }
    $this->render_time = microtime(TRUE) - $start;
    return $this->display_handler->output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TraceableViewExecutable::$render_time protected property
TraceableViewExecutable::getBuildTime public function Gets the build time.
TraceableViewExecutable::getExecuteTime public function Gets the execute time.
TraceableViewExecutable::getRenderTime public function Gets the render time.
TraceableViewExecutable::render public function Render this view for a certain display. Overrides ViewExecutable::render
ViewExecutable::$ajaxEnabled protected property Whether this view uses AJAX.
ViewExecutable::$args public property Any arguments that have been passed into the view.
ViewExecutable::$argument public property Stores the argument handlers which are initialized on this view.
ViewExecutable::$attachment_after public property Attachments to place after the view.
ViewExecutable::$attachment_before public property Attachments to place before the view.
ViewExecutable::$baseEntityType protected property The entity type of the base table, if available.
ViewExecutable::$base_database public property Allow to override the used database which is used for this query.
ViewExecutable::$build_info public property An array of build info.
ViewExecutable::$build_sort public property Indicates if the sorts have been built.
ViewExecutable::$built public property Whether or not the view has been built.
ViewExecutable::$current_display public property Identifier of the current display.
ViewExecutable::$current_page protected property The current page. If the view uses pagination.
ViewExecutable::$displayHandlers public property The list of used displays of the view.
ViewExecutable::$display_handler public property The current used display plugin.
ViewExecutable::$dom_id public property A unique identifier which allows to update multiple views output via js.
ViewExecutable::$element public property A render array container to store render related information.
ViewExecutable::$empty public property Stores the area handlers for the empty text which are initialized on this view.
ViewExecutable::$executed public property Whether the view has been executed/query has been run.
ViewExecutable::$exposed_data public property All the form data from $form_state->getValues().
ViewExecutable::$exposed_input protected property An array of input values from exposed forms.
ViewExecutable::$exposed_raw_input public property Exposed widget input directly from the $form_state->getValues().
ViewExecutable::$exposed_widgets public property The rendered output of the exposed form.
ViewExecutable::$feedIcons public property Feed icons attached to the view.
ViewExecutable::$field public property Stores the field handlers which are initialized on this view.
ViewExecutable::$filter public property Stores the filter handlers which are initialized on this view.
ViewExecutable::$footer public property Stores the area handlers for the footer which are initialized on this view.
ViewExecutable::$get_total_rows public property Force the query to calculate the total number of results.
ViewExecutable::$header public property Stores the area handlers for the header which are initialized on this view.
ViewExecutable::$inited public property Does this view already have loaded its handlers.
ViewExecutable::$is_attachment public property Whether this view is an attachment to another view.
ViewExecutable::$items_per_page protected property The number of items per page.
ViewExecutable::$many_to_one_tables public property Stores the many-to-one tables for performance.
ViewExecutable::$offset protected property The pager offset.
ViewExecutable::$old_view public property Used to store views that were previously running if we recurse.
ViewExecutable::$override_path public property Allow to override the path used for generated urls.
ViewExecutable::$override_url public property Allow to override the url of the current view.
ViewExecutable::$pager public property The used pager plugin used by the current executed view.
ViewExecutable::$parent_views public property To avoid recursion in views embedded into areas.
ViewExecutable::$preview public property If this view has been previewed.
ViewExecutable::$query public property Where the $query object will reside.
ViewExecutable::$relationship public property Stores the relationship handlers which are initialized on this view.
ViewExecutable::$request protected property Stores the current request object.
ViewExecutable::$response protected property Stores the current response object.
ViewExecutable::$result public property Where the results of a query will go.
ViewExecutable::$routeProvider protected property The route provider.
ViewExecutable::$rowPlugin public property The current used row plugin, if the style plugin supports row plugins.
ViewExecutable::$row_index public property Stores the current active row while rendering.
ViewExecutable::$serializationData protected property Holds all necessary data for proper unserialization.
ViewExecutable::$showAdminLinks protected property Should the admin links be shown on the rendered view.
ViewExecutable::$sort public property Stores the sort handlers which are initialized on this view.
ViewExecutable::$storage public property The config entity in which the view is stored.
ViewExecutable::$style_plugin public property The current used style plugin.
ViewExecutable::$total_rows public property The total number of rows returned from the query.
ViewExecutable::$user protected property The current user.
ViewExecutable::$viewsData protected property The views data.
ViewExecutable::access public function Determines if the given user has access to the view.
ViewExecutable::addCacheContext public function Expands the list of used cache contexts for the view.
ViewExecutable::addHandler public function Adds an instance of a handler to the view.
ViewExecutable::ajaxEnabled public function Determines whether or not AJAX should be used.
ViewExecutable::attachDisplays public function Runs attachment displays for the view.
ViewExecutable::build public function Builds the query for the view.
ViewExecutable::buildRenderable public function Builds the render array outline for the given display.
ViewExecutable::buildThemeFunctions public function Provides a full array of possible theme functions to try for a given hook.
ViewExecutable::buildTitle public function Forces the view to build a title.
ViewExecutable::chooseDisplay public function Gets the first display that is accessible to the user.
ViewExecutable::createDuplicate public function Creates a duplicate ViewExecutable object.
ViewExecutable::destroy public function Unsets references so that a $view object may be properly garbage collected.
ViewExecutable::execute public function Executes the view's query.
ViewExecutable::executeDisplay public function Executes the given display, with the given arguments.
ViewExecutable::generateHandlerId public static function Generates a unique ID for an handler instance.
ViewExecutable::getBaseEntityType public function Returns the entity type of the base table, if available.
ViewExecutable::getBaseTables public function Creates a list of base tables to be used by the view.
ViewExecutable::getCacheTags public function Gets the cache tags associated with the executed view.
ViewExecutable::getCurrentPage public function Gets the current page from the pager.
ViewExecutable::getDependencies public function Gets dependencies for the view.
ViewExecutable::getDisplay public function Gets the current display plugin.
ViewExecutable::getExposedInput public function Figures out what the exposed input for this view is.
ViewExecutable::getHandler public function Gets the configuration of a handler instance on a given display.
ViewExecutable::getHandlers public function Gets an array of handler instances for the current display.
ViewExecutable::getHandlerTypes public static function Provides a list of views handler types used in a view.
ViewExecutable::getItemsPerPage public function Gets the items per page from the pager.
ViewExecutable::getOffset public function Gets the pager offset from the pager.
ViewExecutable::getPager public function Gets the current pager plugin.
ViewExecutable::getPath public function Gets the base path used for this view.
ViewExecutable::getPluginTypes public static function Returns the valid types of plugins that can be used.
ViewExecutable::getQuery public function Gets the current query plugin.
ViewExecutable::getRequest public function Gets the request object.
ViewExecutable::getResponse public function Gets the response object used by the view.
ViewExecutable::getShowAdminLinks public function Returns whether admin links should be rendered on the view.
ViewExecutable::getStyle public function Gets the current style plugin.
ViewExecutable::getTitle public function Gets the view's current title.
ViewExecutable::getUrl public function Gets the URL for the current view.
ViewExecutable::getUrlInfo public function Gets the Url object associated with the display handler.
ViewExecutable::getUser public function Gets the current user.
ViewExecutable::hasFormElements public function Determines if this view has form elements.
ViewExecutable::hasUrl public function Determines whether you can link to the view or a particular display.
ViewExecutable::id public function Returns the identifier.
ViewExecutable::initDisplay public function Sets the display for this view and initializes the display handler.
ViewExecutable::initHandlers public function Acquires and attaches all of the handlers.
ViewExecutable::initPager public function Initializes the pager.
ViewExecutable::initQuery public function Initializes the query object for the view.
ViewExecutable::initStyle public function Finds and initializes the style plugin.
ViewExecutable::mergeDefaults public function Merges all plugin default values for each display.
ViewExecutable::newDisplay public function Creates a new display and a display handler instance for it.
ViewExecutable::postExecute public function Unsets the current view, mostly.
ViewExecutable::preExecute public function Runs attachments and lets the display do what it needs to before running.
ViewExecutable::preview public function Previews the given display, with the given arguments.
ViewExecutable::removeHandler public function Removes configuration for a handler instance on a given display.
ViewExecutable::renderPager public function Renders the pager, if necessary.
ViewExecutable::save public function Saves the view.
ViewExecutable::setAjaxEnabled public function Sets whether or not AJAX should be used.
ViewExecutable::setArguments public function Sets the arguments for the view.
ViewExecutable::setCurrentPage public function Sets the current page for the pager.
ViewExecutable::setDisplay public function Sets the current display.
ViewExecutable::setExposedInput public function Sets the exposed filters input to an array.
ViewExecutable::setHandler public function Sets the configuration of a handler instance on a given display.
ViewExecutable::setHandlerOption public function Sets an option on a handler instance.
ViewExecutable::setItemsPerPage public function Sets the items per page on the pager.
ViewExecutable::setOffset public function Sets the offset on the pager.
ViewExecutable::setRequest public function Sets the request object.
ViewExecutable::setResponse public function Sets the used response object of the view.
ViewExecutable::setShowAdminLinks public function Enables admin links on the rendered view.
ViewExecutable::setTitle public function Overrides the view's current title.
ViewExecutable::usePager public function Determines if the view uses a pager.
ViewExecutable::validate public function Makes sure the view is completely valid.
ViewExecutable::_build public function Builds an individual set of handlers.
ViewExecutable::_buildArguments protected function Builds all the arguments.
ViewExecutable::_initHandler protected function Attaches the views handler for the specific type.
ViewExecutable::_postExecute protected function Runs the postExecute() on all active handlers.
ViewExecutable::_preQuery protected function Runs the preQuery() on all active handlers.
ViewExecutable::__construct public function Constructs a new ViewExecutable object.
ViewExecutable::__sleep public function Magic method implementation to serialize the view executable.
ViewExecutable::__wakeup public function Magic method implementation to unserialize the view executable.