Repository URL to install this package:
|
Version:
1.3.0 ▾
|
<?php
namespace Drupal\custom_forms\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\custom_forms\CustomFormsFieldTypeManager;
use Drupal\custom_forms\CustomFormsGroupTypeManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class CustomFormItemActionLink
*
* @package Drupal\custom_forms\Plugin\Derivative
*/
class CustomFormItemActionLink extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* @var EntityTypeManagerInterface $entityTypeManager.
*/
protected $entityTypeManager;
/**
* @var CustomFormsFieldTypeManager $typeManager
*/
protected $typeManager;
/**
* @var CustomFormsGroupTypeManager $groupManager
*/
protected $groupManager;
/**
* Creates a ProductMenuLink instance.
*
* @param $base_plugin_id
* @param EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\custom_forms\CustomFormsFieldTypeManager $type_manager
* @param \Drupal\custom_forms\CustomFormsGroupTypeManager $group_manager
*/
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, CustomFormsFieldTypeManager $type_manager, CustomFormsGroupTypeManager $group_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->typeManager = $type_manager;
$this->groupManager = $group_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('entity_type.manager'),
$container->get('plugin.manager.custom_forms_field_types'),
$container->get('plugin.manager.custom_forms_group_types')
);
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$actions = [];
if (count($this->typeManager->getDefinitions()) > 0) {
$actions['add_field'] = [
'title' => $this->t('Add field'),
'route_name' => 'custom_form.field_list.add_field_form'
] + $base_plugin_definition;
}
if (count($this->groupManager->getDefinitions()) > 0) {
$actions['add_group'] = [
'title' => $this->t('Add group'),
'route_name' => 'custom_form.field_list.add_group_form'
] + $base_plugin_definition;
}
return $actions;
}}