class ParagraphsLockablePlugin in Paragraphs Collection 8
Provides a Paragraphs Lockable plugin.
Plugin annotation
@ParagraphsBehavior(
id = "lockable",
label = @Translation("Lock editing"),
description = @Translation("Prevent from editing without special permission."),
weight = 3
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\paragraphs\ParagraphsBehaviorBase implements ContainerFactoryPluginInterface, ParagraphsBehaviorInterface
- class \Drupal\paragraphs_collection\Plugin\paragraphs\Behavior\ParagraphsLockablePlugin
- class \Drupal\paragraphs\ParagraphsBehaviorBase implements ContainerFactoryPluginInterface, ParagraphsBehaviorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ParagraphsLockablePlugin
1 file declares its use of ParagraphsLockablePlugin
File
- src/
Plugin/ paragraphs/ Behavior/ ParagraphsLockablePlugin.php, line 28
Namespace
Drupal\paragraphs_collection\Plugin\paragraphs\BehaviorView source
class ParagraphsLockablePlugin extends ParagraphsBehaviorBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Constructs a new ParagraphsLockablePlugin object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityFieldManager $entity_field_manager
* Entity Field Manager for base.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* Current user for permissions scope.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManager $entity_field_manager, AccountProxyInterface $currentUser) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_field_manager);
$this->currentUser = $currentUser;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_field.manager'), $container
->get('current_user'));
}
/**
* {@inheritdoc}
*/
public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
// Only display if this plugin is enabled and the user has the permissions.
$form['locked'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Lock content'),
'#description' => $this
->t('If selected this paragraph content will be locked for anyone without the appropriate permission.'),
'#default_value' => $paragraph
->getBehaviorSetting($this
->getPluginId(), 'locked'),
'#access' => $this->currentUser
->hasPermission('administer lockable paragraph'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {
// This implementation of view does nothing.
// As this behavior affects the back end and not the display to the user.
}
/**
* Check the access for the paragraph based on the lockable setting.
*
* Only add content access controls if:
* Not a view operation
* Lockable Behavior is enabled
* Lockable has the locked value set as true.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The paragraph entity.
* @param string $operation
* The current operation.
* @param \Drupal\Core\Session\AccountInterface $account
* The current logged in user.
*
* @return \Drupal\Core\Access\AccessResult
* The access result, will be false if the paragraph is locked
* and the user does not have the appropriate permission.
*/
public static function determineParagraphAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var ParagraphsType $paragraphs_type */
$paragraphs_type = $entity
->getParagraphType();
if ($operation !== 'view' && $entity
->getBehaviorSetting('lockable', 'locked') && $paragraphs_type
->hasEnabledBehaviorPlugin('lockable')) {
$accessResult = AccessResult::forbiddenIf(!$account
->hasPermission('administer lockable paragraph'));
}
else {
$accessResult = AccessResult::neutral();
}
$accessResult
->addCacheableDependency($entity);
$accessResult
->addCacheableDependency($paragraphs_type);
return $accessResult;
}
/**
* {@inheritdoc}
*/
public function settingsSummary(Paragraph $paragraph) {
$locked = $paragraph
->getBehaviorSetting($this
->getPluginId(), 'locked');
$summary = [
[
'value' => $this
->t('Locked'),
],
];
return $locked ? $summary : [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
ParagraphsBehaviorBase:: |
protected | property | The entity field manager. | |
ParagraphsBehaviorBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
2 |
ParagraphsBehaviorBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
2 |
ParagraphsBehaviorBase:: |
protected | function | Removes default behavior form values before storing the user-set ones. | |
ParagraphsBehaviorBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Returns list of field names for the given paragraph type and field type. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public static | function |
Returns if the plugin can be used for the provided Paragraphs type. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Adds a default set of helper variables for preprocessors and templates. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Returns a short info icon for the current behavior settings. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Submit the values taken from the form to store the values. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Validates the behavior fields form. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
ParagraphsLockablePlugin:: |
protected | property | The current user. | |
ParagraphsLockablePlugin:: |
public | function |
Builds a behavior perspective for each paragraph based on its type. Overrides ParagraphsBehaviorBase:: |
|
ParagraphsLockablePlugin:: |
public static | function |
Creates an instance of the plugin. Overrides ParagraphsBehaviorBase:: |
|
ParagraphsLockablePlugin:: |
public static | function | Check the access for the paragraph based on the lockable setting. | |
ParagraphsLockablePlugin:: |
public | function |
Returns a short summary for the current behavior settings. Overrides ParagraphsBehaviorBase:: |
|
ParagraphsLockablePlugin:: |
public | function |
Extends the paragraph render array with behavior. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsLockablePlugin:: |
public | function |
Constructs a new ParagraphsLockablePlugin object. Overrides ParagraphsBehaviorBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |