class ConditionalFieldController in Conditional Fields 8
Same name and namespace in other branches
- 4.x src/Controller/ConditionalFieldController.php \Drupal\conditional_fields\Controller\ConditionalFieldController
Returns responses for conditional_fields module routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\conditional_fields\Controller\ConditionalFieldController
Expanded class hierarchy of ConditionalFieldController
1 file declares its use of ConditionalFieldController
- ConditionalFieldControllerTest.php in tests/
src/ Unit/ ConditionalFieldControllerTest.php
1 string reference to 'ConditionalFieldController'
1 service uses ConditionalFieldController
File
- src/
Controller/ ConditionalFieldController.php, line 19
Namespace
Drupal\conditional_fields\ControllerView source
class ConditionalFieldController extends ControllerBase {
protected $entityTypeManager;
/**
* Form Builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface|EntityFormBuilder
*/
protected $formBuilder;
/**
* Entity type bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* ConditionalFieldController constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
* @param FormBuilderInterface $formBuilder
* Form builder.
* @param EntityTypeBundleInfoInterface $entityTypeBundleInfo
* Entity type bundle info.
* @param EntityFieldManagerInterface $entityFieldManager
* Entity field manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, FormBuilderInterface $formBuilder, EntityTypeBundleInfoInterface $entityTypeBundleInfo, EntityFieldManagerInterface $entityFieldManager) {
$this->entityTypeManager = $entityTypeManager;
$this->formBuilder = $formBuilder;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->entityFieldManager = $entityFieldManager;
}
/**
* Show entity types.
*
* @return array
* Array of page elements to render.
*/
public function entityTypeList() {
$output = [
'#theme' => 'admin_block_content',
'#content' => [],
];
foreach ($this
->getEntityTypes() as $key => $entityType) {
$output['#content'][] = [
'url' => Url::fromRoute('conditional_fields.bundle_list', [
'entity_type' => $key,
]),
'title' => $entityType
->getLabel(),
];
}
return $output;
}
/**
* Title for fields form.
*
* @param string $entity_type
* Entity type.
* @param string $bundle
* Entity bundle.
*
* @return string
* Page title.
*/
public function formTitle($entity_type, $bundle) {
$bundles = $this->entityTypeBundleInfo
->getBundleInfo($entity_type);
if (!isset($bundles[$bundle]['label'])) {
return '';
}
return $bundles[$bundle]['label'];
}
/**
* Title for field settings form.
*
* @param string $entity_type
* Entity type.
* @param string $bundle
* Entity bundle.
* @param string $field_name
* Field name.
*
* @return string
* Page title.
*/
public function editFormTitle($entity_type, $bundle, $field_name) {
$instances = $this->entityFieldManager
->getFieldDefinitions($entity_type, $bundle);
if (!isset($instances[$field_name])) {
return '';
}
$field_instance = $instances[$field_name];
return $field_instance
->getLabel();
}
/**
* Title for bundle list of current entity type.
*
* @param string $entity_type
* Entity type.
*
* @return string The title for the bundle list page.
* The title for the bundle list page.
*/
public function bundleListTitle($entity_type) {
$type = $this->entityTypeManager
->getDefinition($entity_type);
return $type
->getLabel();
}
/**
* Show bundle list of current entity type.
*
* @param string $entity_type
* Entity type.
*
* @return array Array of page elements to render.
* Array of page elements to render.
*/
public function bundleList($entity_type) {
$output = [];
$bundles = $this->entityTypeBundleInfo
->getBundleInfo($entity_type);
if ($bundles) {
$output['#theme'] = 'admin_block_content';
foreach ($bundles as $bundle_key => $bundle) {
$output['#content'][] = [
'url' => Url::fromRoute('conditional_fields.conditions_list', [
'entity_type' => $entity_type,
'bundle' => $bundle_key,
]),
'title' => $bundle['label'],
];
}
}
else {
$output['#type'] = 'markup';
$output['#markup'] = $this
->t("Bundles not found");
}
return $output;
}
/**
* Get list of available EntityTypes.
*
* @return ContentEntityTypeInterface[]
* List of content entity types.
*/
public function getEntityTypes() {
$entityTypes = [];
foreach ($this->entityTypeManager
->getDefinitions() as $key => $entityType) {
if ($entityType instanceof ContentEntityType) {
$entityTypes[$key] = $entityType;
}
}
return $entityTypes;
}
/**
* Provide arguments for ConditionalFieldFormTab.
*
* @param string $node_type
* Node type.
*
* @return array
* Form array.
*/
public function provideArguments($node_type) {
return $this->formBuilder
->getForm(ConditionalFieldFormTab::class, 'node', $node_type);
}
/**
* Provide arguments for ConditionalFieldFormTab.
*
* @param string $node_type
* Node type.
*
* @return array
* Form array.
*/
public function getMediaEditFormTab($media_type) {
return $this->formBuilder
->getForm(ConditionalFieldFormTab::class, 'media', $media_type);
}
/**
* Provide arguments for ConditionalFieldFormTab.
*
* @param string $node_type
* Node type.
*
* @return array
* Form array.
*/
public function getBlockEditFormTab($block_content_type) {
return $this->formBuilder
->getForm(ConditionalFieldFormTab::class, 'block_content', $block_content_type);
}
/**
* Provide arguments for ConditionalFieldFormTab.
*
* @param string $node_type
* Node type.
*
* @return array
* Form array.
*/
public function getCommentEditFormTab($comment_type) {
return $this->formBuilder
->getForm(ConditionalFieldFormTab::class, 'comment', $comment_type);
}
/**
* Provide arguments for ConditionalFieldFormTab.
*
* @param string $node_type
* Node type.
*
* @return array
* Form array.
*/
public function getUserEditFormTab() {
$user_type = "user";
return $this->formBuilder
->getForm(ConditionalFieldFormTab::class, 'user', $user_type);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionalFieldController:: |
protected | property | Entity field manager. | |
ConditionalFieldController:: |
protected | property | Entity type bundle info. | |
ConditionalFieldController:: |
protected | property |
The entity type manager. Overrides ControllerBase:: |
|
ConditionalFieldController:: |
protected | property |
Form Builder. Overrides ControllerBase:: |
|
ConditionalFieldController:: |
public | function | Show bundle list of current entity type. | |
ConditionalFieldController:: |
public | function | Title for bundle list of current entity type. | |
ConditionalFieldController:: |
public | function | Title for field settings form. | |
ConditionalFieldController:: |
public | function | Show entity types. | |
ConditionalFieldController:: |
public | function | Title for fields form. | |
ConditionalFieldController:: |
public | function | Provide arguments for ConditionalFieldFormTab. | |
ConditionalFieldController:: |
public | function | Provide arguments for ConditionalFieldFormTab. | |
ConditionalFieldController:: |
public | function | Get list of available EntityTypes. | |
ConditionalFieldController:: |
public | function | Provide arguments for ConditionalFieldFormTab. | |
ConditionalFieldController:: |
public | function | Provide arguments for ConditionalFieldFormTab. | |
ConditionalFieldController:: |
public | function | Provide arguments for ConditionalFieldFormTab. | |
ConditionalFieldController:: |
public | function | ConditionalFieldController constructor. | |
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
40 |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |