8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Routing\RouteMatchInterface;
10 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
12 use Drupal\linkit\ProfileInterface;
15 * Implements hook_help().
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>';
27 * Implements hook_form_BASE_FORM_ID_alter() for linkit_profile_form on behalf
28 * of the 'imce' module.
30 * Adds IMCE settings to the form.
32 * @see imce_form_linkit_profile_form_builder()
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();
38 $form['imce'] = array(
40 '#title' => t('IMCE integration'),
41 '#group' => 'additional_settings',
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),
50 $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::READ_VISIBLE);
51 $form['imce']['imce_scheme'] = array(
53 '#title' => t('Scheme'),
54 '#options' => $scheme_options,
55 '#default_value' => $linkit_profile->getThirdPartySetting('imce', 'scheme', 'public'),
58 ':input[name="imce_use"]' => ['checked' => TRUE],
63 $form['#entity_builders'][] = 'imce_form_linkit_profile_form_builder';
67 * Entity builder for the linkit profile form with imce options.
69 * @see imce_form_linkit_profile_form_alter().
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'));
77 * Implements hook_form_BASE_FORM_ID_alter() for linkit_editor_dialog_form on
78 * behalf of the 'imce' module.
80 * Adds a button to open the imce file browser if it is enabled.
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();
86 if($linkit_profile->getThirdPartySetting('imce', 'use', FALSE)) {
87 $form['imce-link'] = [
89 '#title' => t('Open IMCE file browser'),
90 '#url' => Url::fromRoute('imce.page', [
91 'scheme' => $linkit_profile->getThirdPartySetting('imce', 'scheme', 'public'),
95 'sendto' => 'linkitImce.sendto',
99 'class' => ['linkit-imce-open'],