You are here

class BookSitemapDeriver in Sitemap 8.2

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Derivative/BookSitemapDeriver.php \Drupal\sitemap\Plugin\Derivative\BookSitemapDeriver

Hierarchy

Expanded class hierarchy of BookSitemapDeriver

File

src/Plugin/Derivative/BookSitemapDeriver.php, line 13

Namespace

Drupal\sitemap\Plugin\Derivative
View source
class BookSitemapDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The book manager.
   *
   * @var \Drupal\book\BookManagerInterface
   */
  protected $bookManager;

  /**
   * Constructs new SitemapBooks sitemap_map.
   *
   * @param \Drupal\book\BookManagerInterface $book_manager
   *   The book manager.
   */
  public function __construct(BookManagerInterface $book_manager) {
    $this->bookManager = $book_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    if (\Drupal::moduleHandler()
      ->moduleExists('book')) {
      return new static($container
        ->get('book.manager'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (\Drupal::moduleHandler()
      ->moduleExists('book')) {
      foreach ($this->bookManager
        ->getAllBooks() as $id => $book) {
        $this->derivatives[$id] = $base_plugin_definition;
        $this->derivatives[$id]['title'] = t('Book: @book', [
          '@book' => $book['title'],
        ]);
        $this->derivatives[$id]['description'] = $book['type'];
        $this->derivatives[$id]['settings']['title'] = '';
        $this->derivatives[$id]['book'] = $id;
        $this->derivatives[$id]['config_dependencies']['config'] = [
          'book.settings',
        ];
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BookSitemapDeriver::$bookManager protected property The book manager.
BookSitemapDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
BookSitemapDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
BookSitemapDeriver::__construct public function Constructs new SitemapBooks sitemap_map.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition