You are here

class NgLightboxServiceProvider in NG Lightbox 8

Same name and namespace in other branches
  1. 2.x src/NgLightboxServiceProvider.php \Drupal\ng_lightbox\NgLightboxServiceProvider

The NgLightboxServiceProvider class.

Hierarchy

Expanded class hierarchy of NgLightboxServiceProvider

File

src/NgLightboxServiceProvider.php, line 16
Contains \Drupal\ng_lightbox\NgLightboxServiceProvider

Namespace

Drupal\ng_lightbox
View source
class NgLightboxServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
    $container
      ->addCompilerPass(new NgLightboxPass());
  }

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    $this
      ->addLightbox($container, 'main_content_renderer.dialog', 'Core Dialog');
    $this
      ->addLightbox($container, 'main_content_renderer.modal', 'Core Modal');
  }

  /**
   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
   * @param $id
   * @param $title
   */
  protected function addLightbox(ContainerBuilder $container, $id, $title) {
    $definition = $container
      ->getDefinition($id);
    $tags = $definition
      ->getTags();
    foreach ($tags as $delta => &$tag) {
      if ($delta === 'render.main_content_renderer') {
        foreach ($tag as &$attribute) {
          $attribute['ng_lightbox'] = $title;
        }
      }
    }
    $definition
      ->setTags($tags);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NgLightboxServiceProvider::addLightbox protected function
NgLightboxServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
NgLightboxServiceProvider::register public function Registers services to the container. Overrides ServiceProviderBase::register