function LoadLibraryController::build

A simple page with a library attached.

Return value

array A render array.

1 string reference to 'LoadLibraryController::build'
modernizr_deprecation_test.routing.yml in core/modules/system/tests/modules/modernizr_deprecation_test/modernizr_deprecation_test.routing.yml
core/modules/system/tests/modules/modernizr_deprecation_test/modernizr_deprecation_test.routing.yml

File

core/modules/system/tests/modules/modernizr_deprecation_test/src/Controller/LoadLibraryController.php, line 36

Class

LoadLibraryController
A page to facilitate library loading.

Namespace

Drupal\modernizr_deprecation_test\Controller

Code

public function build($extension, $library) {
    // Confirm the extension and library are valid before proceeding.
    $extension_list = array_keys($this->moduleExtensionList
        ->getList());
    array_push($extension_list, 'core');
    assert(in_array($extension, $extension_list), "Extension {$extension} not available.");
    $available_libraries = $this->libraryDiscovery
        ->getLibrariesByExtension($extension);
    assert(isset($available_libraries[$library]), "Library {$library} not available in extension {$extension}");
    $build = [
        '#markup' => "Attaching {$extension}/{$library}",
        '#cache' => [
            'max-age' => 0,
        ],
    ];
    $build['#attached']['library'][] = "{$extension}/{$library}";
    if ($library === 'modernizr') {
        $build['#attached']['library'][] = 'modernizr_deprecation_test/access_unsupported_property';
    }
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.