View source
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Url;
use Drupal\linkit\ProfileInterface;
function linkit_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'entity.linkit_profile.attributes':
return '<p>' . t('Attributes are HTML attributes that will be attached to the insert plugin.') . '</p>';
break;
}
}
function imce_form_linkit_profile_form_alter(&$form, FormStateInterface $form_state) {
$linkit_profile = $form_state
->getFormObject()
->getEntity();
$form['imce'] = array(
'#type' => 'details',
'#title' => t('IMCE integration'),
'#group' => 'additional_settings',
);
$form['imce']['imce_use'] = array(
'#type' => 'checkbox',
'#title' => t('Enable IMCE File Browser in the editor dialog.'),
'#default_value' => $linkit_profile
->getThirdPartySetting('imce', 'use', FALSE),
);
$scheme_options = \Drupal::service('stream_wrapper_manager')
->getNames(StreamWrapperInterface::READ_VISIBLE);
$form['imce']['imce_scheme'] = array(
'#type' => 'radios',
'#title' => t('Scheme'),
'#options' => $scheme_options,
'#default_value' => $linkit_profile
->getThirdPartySetting('imce', 'scheme', 'public'),
'#states' => [
'visible' => [
':input[name="imce_use"]' => [
'checked' => TRUE,
],
],
],
);
$form['#entity_builders'][] = 'imce_form_linkit_profile_form_builder';
}
function imce_form_linkit_profile_form_builder($entity_type, ProfileInterface $linkit_profile, &$form, FormStateInterface $form_state) {
$linkit_profile
->setThirdPartySetting('imce', 'use', $form_state
->getValue('imce_use'));
$linkit_profile
->setThirdPartySetting('imce', 'scheme', $form_state
->getValue('imce_scheme'));
}
function imce_form_linkit_editor_dialog_form_alter(&$form, FormStateInterface $form_state) {
$linkit_profile = $form_state
->getFormObject()
->getLinkitProfile();
if ($linkit_profile
->getThirdPartySetting('imce', 'use', FALSE)) {
$form['imce-link'] = [
'#type' => 'link',
'#title' => t('Open IMCE file browser'),
'#url' => Url::fromRoute('imce.page', [
'scheme' => $linkit_profile
->getThirdPartySetting('imce', 'scheme', 'public'),
]),
'#options' => array(
'query' => array(
'sendto' => 'linkitImce.sendto',
),
),
'#attributes' => [
'class' => [
'linkit-imce-open',
],
],
'#attached' => [
'library' => [
'linkit/linkit.imce',
],
],
'#weight' => 1,
];
}
}