You are here

public function ParagraphsLockablePlugin::buildBehaviorForm in Paragraphs Collection 8

Builds a behavior perspective for each paragraph based on its type.

This method is responsible for building the behavior form for each Paragraph so the user can set special attributes and properties.

Parameters

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The fields build array that the plugin creates.

Overrides ParagraphsBehaviorBase::buildBehaviorForm

File

src/Plugin/paragraphs/Behavior/ParagraphsLockablePlugin.php, line 66

Class

ParagraphsLockablePlugin
Provides a Paragraphs Lockable plugin.

Namespace

Drupal\paragraphs_collection\Plugin\paragraphs\Behavior

Code

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;
}