3 namespace Drupal\paragraphs;
5 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\PluginFormInterface;
8 use Drupal\Component\Plugin\ConfigurablePluginInterface;
9 use Drupal\paragraphs\Entity\Paragraph;
10 use Drupal\paragraphs\Entity\ParagraphsType;
13 * Provides an interface defining a paragraph behavior.
15 * A paragraph behavior plugin adds extra functionality to the paragraph such as
16 * adding properties and attributes, it can also add extra classes to the render
17 * elements so extra styling can be applied.
19 interface ParagraphsBehaviorInterface extends PluginFormInterface, ConfigurablePluginInterface {
22 * Builds a behavior perspective for each paragraph based on its type.
24 * This method is responsible for building the behavior form for each
25 * Paragraph so the user can set special attributes and properties.
27 * @param \Drupal\paragraphs\ParagraphInterface $paragraph
30 * An associative array containing the initial structure of the plugin form.
31 * @param \Drupal\Core\Form\FormStateInterface $form_state
32 * The current state of the form.
35 * The fields build array that the plugin creates.
37 public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state);
40 * Validates the behavior fields form.
42 * This method is responsible for validating the data in the behavior fields
43 * form and displaying validation messages.
45 * @param \Drupal\paragraphs\ParagraphInterface $paragraph
48 * An associative array containing the initial structure of the plugin form.
49 * @param \Drupal\Core\Form\FormStateInterface $form_state
50 * The current state of the form.
52 public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state);
55 * Submit the values taken from the form to store the values.
57 * This method is responsible for submitting the data and saving it in the
60 * @param \Drupal\paragraphs\ParagraphInterface $paragraph
63 * An associative array containing the initial structure of the plugin form.
64 * @param \Drupal\Core\Form\FormStateInterface $form_state
65 * The current state of the form.
67 public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state);
70 * Adds a default set of helper variables for preprocessors and templates.
72 * This preprocess function is the first in the sequence of preprocessing
73 * functions that are called when preparing variables of a paragraph.
75 * @param array $variables
76 * An associative array containing:
77 * - elements: An array of elements to display in view mode.
78 * - paragraph: The paragraph object.
79 * - view_mode: The view mode.
81 public function preprocess(&$variables);
84 * Extends the paragraph render array with behavior.
86 * @param array &$build
87 * A renderable array representing the paragraph. The module may add
88 * elements to $build prior to rendering. The structure of $build is a
89 * renderable array as expected by drupal_render().
90 * @param \Drupal\paragraphs\Entity\Paragraph $paragraph
92 * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
93 * The entity view display holding the display options configured for the
95 * @param string $view_mode
96 * The view mode the entity is rendered in.
99 * A render array provided by the plugin.
101 public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode);
104 * Returns if the plugin can be used for the provided paragraphs type.
106 * @param \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type
107 * The paragraphs type entity that should be checked.
110 * TRUE if the formatter can be used, FALSE otherwise.
112 public static function isApplicable(ParagraphsType $paragraphs_type);
115 * Returns a short summary for the current behavior settings.
117 * @param \Drupal\paragraphs\Entity\Paragraph $paragraph
121 * The plugin settings.
123 public function settingsSummary(Paragraph $paragraph);
126 * Returns list of field names for the given paragraph type and field type.
129 * @param \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type
130 * The paragraphs type entity.
131 * @param string $field_type
132 * (optional) Field type to check for existence. If field type is not
133 * provided, returns all entity fields.
136 * The list of field labels keyed by their field name.
138 public function getFieldNameOptions(ParagraphsType $paragraphs_type, $field_type = NULL);