Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds / src / Plugin / Derivative / UtilityMenuLink.php
Size: Mime:
<?php


namespace Drupal\dds\Plugin\Derivative;


use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

class UtilityMenuLink extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * @var \Drupal\Core\Routing\RouteProviderInterface $routeProvider
   */
  protected $routeProvider;

  /**
   * Creates a UtilityMenuLink instance.
   *
   * @param $base_plugin_id
   */
  public function __construct($base_plugin_id, RouteProviderInterface $route_provider) {
    $this->routeProvider = $route_provider;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static(
      $base_plugin_id,
      $container->get('router.route_provider')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $config = \Drupal::config('dds.utilities');

    $links = [];
    // Because drupal also saves values of unchecked checkboxes, we need to
    // filter those out.
    if (!empty($config->get('enabled'))) {
      foreach ($config->get('enabled') as $key => $value) {
        if ($value === $key) {
          switch ($key) {
            // Add no-follow/no-index menu item
            case 'nofollow_noindex':
              // Only add it if the route exists to avoid routing errors.
              if (count($this->routeProvider->getRoutesByNames(['dds.utilities.nofollow_form'])) === 1) {
                $links['nofollow_noindex'] = [
                    'title' => $this->t('No-follow / No-index'),
                    'route_name' => 'dds.utilities.nofollow_form',
                    'route_parameters' => [],
                  ] + $base_plugin_definition;
              }
              break;
          }
        }
      }
    }

    return $links;
  }
}