You are here

class AlinksController in Alinks 8

Returns responses for alinks configuration routes.

Hierarchy

Expanded class hierarchy of AlinksController

File

src/Controller/AlinksController.php, line 14

Namespace

Drupal\alinks\Controller
View source
class AlinksController implements ContainerInjectionInterface {

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a new controller.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The configuration factory.
   */
  public function __construct(ConfigFactoryInterface $configFactory) {
    $this->configFactory = $configFactory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'));
  }

  /**
   * Remove the given entity type, bundle and display from alinks configuration.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   *   Return a redirect to the alinks settings page.
   */
  public function delete($entity_type, $entity_bundle, $entity_display) {
    $config = $this->configFactory
      ->getEditable('alinks.settings');
    $displays = array_values(array_filter($config
      ->get('displays'), function ($display) use ($entity_type, $entity_bundle, $entity_display) {
      return !($display['entity_type'] == $entity_type && $display['entity_bundle'] == $entity_bundle && $display['entity_display'] == $entity_display);
    }));
    $config
      ->set('displays', $displays)
      ->save();
    return new RedirectResponse(Url::fromRoute('alink_keyword.settings')
      ->setAbsolute()
      ->toString());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AlinksController::$configFactory protected property The configuration factory.
AlinksController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
AlinksController::delete public function Remove the given entity type, bundle and display from alinks configuration.
AlinksController::__construct public function Constructs a new controller.