You are here

JsInjector.php in Asset Injector 8

File

src/Entity/JsInjector.php
View source
<?php

namespace Drupal\asset_injector\Entity;


/**
 * Defines the Js Injector entity.
 *
 * @ConfigEntityType(
 *   id = "js_injector",
 *   label = @Translation("Js Injector"),
 *   list_cache_tags = { "library_info" },
 *   handlers = {
 *     "list_builder" = "Drupal\asset_injector\AssetInjectorListBuilder",
 *     "form" = {
 *       "add" = "Drupal\asset_injector\Form\JsInjectorForm",
 *       "edit" = "Drupal\asset_injector\Form\JsInjectorForm",
 *       "delete" = "Drupal\asset_injector\Form\AssetInjectorDeleteForm",
 *       "enable" = "Drupal\asset_injector\Form\AssetInjectorEnableForm",
 *       "disable" = "Drupal\asset_injector\Form\AssetInjectorDisableForm",
 *       "duplicate" = "Drupal\asset_injector\Form\JsInjectorDuplicateForm",
 *     }
 *   },
 *   config_prefix = "js_injector",
 *   admin_permission = "administer js assets injector",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "status" = "status",
 *   },
 *   links = {
 *     "canonical" = "/admin/config/development/asset-injector/js/{js_injector}",
 *     "edit-form" = "/admin/config/development/asset-injector/js/{js_injector}/edit",
 *     "delete-form" = "/admin/config/development/asset-injector/js/{js_injector}/delete",
 *     "enable" = "/admin/config/development/asset-injector/js/{js_injector}/enable",
 *     "disable" = "/admin/config/development/asset-injector/js/{js_injector}/disable",
 *     "collection" = "/admin/structure/visibility_group"
 *   }
 * )
 */
class JsInjector extends AssetInjectorBase {

  /**
   * Load js in the header of the page.
   *
   * @var bool
   */
  public $header;

  /**
   * Preprocess css before adding.
   *
   * @var bool
   */
  public $preprocess = TRUE;

  /**
   * Require jquery.
   *
   * @var string
   */
  public $jquery = FALSE;

  /**
   * Gets the file extension of the asset.
   *
   * @return string
   *   JS extension.
   */
  public function extension() {
    return 'js';
  }

  /**
   * {@inheritdoc}
   */
  public function libraryInfo() {
    $path = $this
      ->filePathRelativeToDrupalRoot();
    $library_info = [
      'header' => $this->header,
      'js' => [
        $path => [
          'preprocess' => $this->preprocess,
        ],
      ],
    ];
    if ($this->jquery) {
      $library_info['dependencies'] = [
        'core/jquery',
      ];
    }
    return $library_info;
  }

}

Classes

Namesort descending Description
JsInjector Defines the Js Injector entity.