Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Element / ParagraphsActions.php
1 <?php
2
3 namespace Drupal\paragraphs\Element;
4
5 use Drupal\Core\Render\Element;
6 use Drupal\Core\Render\Element\RenderElement;
7
8 /**
9  * Provides a render element for a paragraphs actions.
10  *
11  * Paragraphs actions can have two type of actions
12  * - actions - this are default actions that are always visible.
13  * - dropdown_actions - actions that are in dropdown sub component.
14  *
15  * Usage example:
16  *
17  * @code
18  * $form['actions'] = [
19  *   '#type' => 'paragraphs_actions',
20  *   'actions' => $actions,
21  *   'dropdown_actions' => $dropdown_actions,
22  * ];
23  * $dropdown_actions['button'] = array(
24  *   '#type' => 'submit',
25  * );
26  * @endcode
27  *
28  * @FormElement("paragraphs_actions")
29  */
30 class ParagraphsActions extends RenderElement {
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getInfo() {
36     $class = get_class($this);
37
38     return [
39       '#pre_render' => [
40         [$class, 'preRenderParagraphsActions'],
41       ],
42       '#theme' => 'paragraphs_actions',
43     ];
44   }
45
46   /**
47    * Pre render callback for #type 'paragraphs_actions'.
48    *
49    * @param array $element
50    *   Element arrar of a #type 'paragraphs_actions'.
51    *
52    * @return array
53    *   The processed element.
54    */
55   public static function preRenderParagraphsActions(array $element) {
56     $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.actions';
57
58     if (!empty($element['dropdown_actions'])) {
59       foreach (Element::children($element['dropdown_actions']) as $key) {
60         $dropdown_action = &$element['dropdown_actions'][$key];
61         if (isset($dropdown_action['#ajax'])) {
62           $dropdown_action = RenderElement::preRenderAjaxForm($dropdown_action);
63         }
64         if (empty($dropdown_action['#attributes'])) {
65           $dropdown_action['#attributes'] = ['class' => ['paragraphs-dropdown-action']];
66         }
67         else {
68           $dropdown_action['#attributes']['class'][] = 'paragraphs-dropdown-action';
69         }
70       }
71     }
72
73     return $element;
74   }
75
76 }