Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / linkit.module
1 <?php
2
3 /**
4  * @file
5  *
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Routing\RouteMatchInterface;
10 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
11 use Drupal\Core\Url;
12 use Drupal\linkit\ProfileInterface;
13
14 /**
15  * Implements hook_help().
16  */
17 function linkit_help($route_name, RouteMatchInterface $route_match) {
18   switch ($route_name) {
19     case 'entity.linkit_profile.attributes':
20       return '<p>' . t('Attributes are HTML attributes that will be attached to the insert plugin.') . '</p>';
21       break;
22   }
23 }
24
25
26 /**
27  * Implements hook_form_BASE_FORM_ID_alter() for linkit_profile_form on behalf
28  * of the 'imce' module.
29  *
30  * Adds IMCE settings to the form.
31  *
32  * @see imce_form_linkit_profile_form_builder()
33  */
34 function imce_form_linkit_profile_form_alter(&$form, FormStateInterface $form_state) {
35   /** @var \Drupal\Linkit\ProfileInterface $linkit_profile */
36   $linkit_profile = $form_state->getFormObject()->getEntity();
37
38   $form['imce'] = array(
39     '#type' => 'details',
40     '#title' => t('IMCE integration'),
41     '#group' => 'additional_settings',
42   );
43
44   $form['imce']['imce_use'] = array(
45     '#type' => 'checkbox',
46     '#title' => t('Enable IMCE File Browser in the editor dialog.'),
47     '#default_value' => $linkit_profile->getThirdPartySetting('imce', 'use', FALSE),
48   );
49
50   $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::READ_VISIBLE);
51   $form['imce']['imce_scheme'] = array(
52     '#type' => 'radios',
53     '#title' => t('Scheme'),
54     '#options' => $scheme_options,
55     '#default_value' => $linkit_profile->getThirdPartySetting('imce', 'scheme', 'public'),
56     '#states' => [
57       'visible' => [
58         ':input[name="imce_use"]' => ['checked' => TRUE],
59       ],
60     ],
61   );
62
63   $form['#entity_builders'][] = 'imce_form_linkit_profile_form_builder';
64 }
65
66 /**
67  * Entity builder for the linkit profile form with imce options.
68  *
69  * @see imce_form_linkit_profile_form_alter().
70  */
71 function imce_form_linkit_profile_form_builder($entity_type, ProfileInterface $linkit_profile, &$form, FormStateInterface $form_state) {
72   $linkit_profile->setThirdPartySetting('imce', 'use', $form_state->getValue('imce_use'));
73   $linkit_profile->setThirdPartySetting('imce', 'scheme', $form_state->getValue('imce_scheme'));
74 }
75
76 /**
77  * Implements hook_form_BASE_FORM_ID_alter() for linkit_editor_dialog_form on
78  * behalf of the 'imce' module.
79  *
80  * Adds a button to open the imce file browser if it is enabled.
81  */
82 function imce_form_linkit_editor_dialog_form_alter(&$form, FormStateInterface $form_state) {
83   /** @var \Drupal\Linkit\ProfileInterface $linkit_profile */
84   $linkit_profile = $form_state->getFormObject()->getLinkitProfile();
85
86   if($linkit_profile->getThirdPartySetting('imce', 'use', FALSE)) {
87     $form['imce-link'] = [
88       '#type' => 'link',
89       '#title' => t('Open IMCE file browser'),
90       '#url' => Url::fromRoute('imce.page', [
91         'scheme' => $linkit_profile->getThirdPartySetting('imce', 'scheme', 'public'),
92       ]),
93       '#options' => array(
94         'query' => array(
95           'sendto' => 'linkitImce.sendto',
96         ),
97       ),
98       '#attributes' => [
99         'class' => ['linkit-imce-open'],
100       ],
101       '#attached' => [
102         'library' => [
103           'linkit/linkit.imce'
104         ],
105       ],
106       '#weight' => 1,
107     ];
108   }
109 }