Problem/Motivation

Original code:

 /**
   * Loads a view from configuration and returns its executable object.
   *
   * @param string $id
   *   The view ID to load.
   *
   * @return \Drupal\views\ViewExecutable
   *   A view executable instance, from the loaded entity.
   */
  public static function getView($id) {
    $view = \Drupal::entityTypeManager()->getStorage('view')->load($id);
    if ($view) {
      return static::executableFactory()->get($view);
    }
  }

Proposed resolution

 /**
   * Loads a view from configuration and returns its executable object.
   *
   * @param string $id
   *   The view ID to load.
   *
   * @return \Drupal\views\ViewExecutable|null
   *   A view executable instance, from the loaded entity.
   */
  public static function getView($id) {
    $view = \Drupal::entityTypeManager()->getStorage('view')->load($id);
    if ($view) {
      return static::executableFactory()->get($view);
    }
    return NULL;
  }

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jungle created an issue. See original summary.

munish.kumar’s picture

Assigned: Unassigned » munish.kumar
jungle’s picture


   * @return \Drupal\views\ViewExecutable|null
   *   A view executable instance, from the loaded entity.

Thanks, @munish.kumar for picking it up, just a reminder, the comment "A view executable instance, from the loaded entity." should be updated as well.

munish.kumar’s picture

Assigned: munish.kumar » Unassigned
Status: Active » Needs review
StatusFileSize
new778 bytes

Thanks @jungle for pointing these changes as well. As discussed I have updated the comment in the patch. Please review.

Status: Needs review » Needs work

The last submitted patch, 4: 3150474-4.patch, failed testing. View results

jungle’s picture

Status: Needs work » Needs review

A random failure, re-queued.

siddhant.bhosale’s picture

Assigned: Unassigned » siddhant.bhosale
jungle’s picture

StatusFileSize
new1.29 KB
new1.89 KB
new2.05 KB

Added a test "Tests the getView() method against a non-existent view.", but the test-only patch will pass, as by default if the return statement is missing, it returns NULL.

siddhant.bhosale’s picture

Assigned: siddhant.bhosale » Unassigned
Status: Needs review » Reviewed & tested by the community

Hi, I have tested the patch and looks good to be merged.

alexpott’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 19d2c39d0d to 9.1.x and e8cdb1d61f to 9.0.x and fd046df3d9 to 8.9.x. Thanks!

  • alexpott committed 19d2c39 on 9.1.x
    Issue #3150474 by jungle, munish.kumar: Inaccurate return type of \...

  • alexpott committed e8cdb1d on 9.0.x
    Issue #3150474 by jungle, munish.kumar: Inaccurate return type of \...

  • alexpott committed fd046df on 8.9.x
    Issue #3150474 by jungle, munish.kumar: Inaccurate return type of \...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.