diff --git a/config/schema/linkit.schema.yml b/config/schema/linkit.schema.yml index e349fe0..d8f617f 100644 --- a/config/schema/linkit.schema.yml +++ b/config/schema/linkit.schema.yml @@ -10,43 +10,11 @@ linkit.linkit_profile.*: type: string description: type: string - attributes: - type: sequence - sequence: - type: linkit.attribute matchers: type: sequence sequence: type: linkit.matcher -linkit.attribute: - type: mapping - mapping: - id: - type: string - settings: - type: linkit.attribute.[%parent.id] - weight: - type: integer - -linkit.attribute.*: - type: mapping - label: 'Attribute settings' - -# Plugin \Drupal\linkit\Plugin\Linkit\Attribute\Target -linkit.attribute.target: - type: linkit.attribute - mapping: - widget_type: - type: string - -# Plugin \Drupal\linkit\Plugin\Linkit\Attribute\Title -linkit.attribute.title: - type: linkit.attribute - mapping: - automatic_title: - type: boolean - linkit.matcher: type: mapping mapping: diff --git a/css/linkit.admin.theme.css b/css/linkit.admin.theme.css index c4afd11..7a668a7 100644 --- a/css/linkit.admin.theme.css +++ b/css/linkit.admin.theme.css @@ -9,7 +9,6 @@ line-height: 1.2em; } -.linkit-matcher-add-form tbody td:first-child, -.linkit-attribute-add-form tbody td:first-child { +.linkit-matcher-add-form tbody td:first-child { width: 1%; } diff --git a/js/attribute/title.js b/js/attribute/title.js deleted file mode 100644 index a2bb7a1..0000000 --- a/js/attribute/title.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @file - * Title attribute functions. - */ - -(function ($, Drupal, document) { - - 'use strict'; - - var fieldName = '[name="attributes[title]"]'; - - /** - * Automatically populate the title attribute. - */ - $(document).bind('linkit.autocomplete.select', function (triggerEvent, event, ui) { - if (ui.item.hasOwnProperty('title')) { - $('form.linkit-editor-dialog-form').find(fieldName).val(ui.item.title); - } - }); - -})(jQuery, Drupal, document); diff --git a/js/plugins/linkit/linkit.png b/js/plugins/linkit/linkit.png deleted file mode 100644 index 90fc72e..0000000 Binary files a/js/plugins/linkit/linkit.png and /dev/null differ diff --git a/js/plugins/linkit/plugin.js b/js/plugins/linkit/plugin.js deleted file mode 100644 index e3fd0ce..0000000 --- a/js/plugins/linkit/plugin.js +++ /dev/null @@ -1,223 +0,0 @@ -/** - * @file - * Linkit plugin. - * - * @ignore - */ - -(function ($, Drupal, drupalSettings, CKEDITOR) { - - 'use strict'; - - // Alter the dialog settings to make a bigger dialog. - // $(window).on('dialog:beforecreate', function (event, dialog, $element, settings) { - // settings.dialogClass = settings.dialogClass.replace('ui-dialog--narrow', ''); - // settings.width = 700; - // }); - - CKEDITOR.plugins.add('linkit', { - init: function (editor) { - // Add the commands for link and unlink. - editor.addCommand('linkit', { - allowedContent: new CKEDITOR.style({ - element: 'a', - attributes: { - '!href': '', - // @TODO: Read these dynamically from the profile. - 'accesskey': '', - 'id': '', - 'rel': '', - 'target': '', - 'title': '' - } - }), - requiredContent: new CKEDITOR.style({ - element: 'a', - attributes: { - href: '' - } - }), - modes: {wysiwyg: 1}, - canUndo: true, - exec: function (editor) { - var linkElement = getSelectedLink(editor); - var linkDOMElement = null; - - // Set existing values based on selected element. - var existingValues = {}; - if (linkElement && linkElement.$) { - linkDOMElement = linkElement.$; - - // Populate an array with the link's current attributes. - var attribute = null; - var attributeName; - for (var attrIndex = 0; attrIndex < linkDOMElement.attributes.length; attrIndex++) { - attribute = linkDOMElement.attributes.item(attrIndex); - attributeName = attribute.nodeName.toLowerCase(); - // Don't consider data-cke-saved- attributes; they're just there - // to work around browser quirks. - if (attributeName.substring(0, 15) === 'data-cke-saved-') { - continue; - } - // Store the value for this attribute, unless there's a - // data-cke-saved- alternative for it, which will contain the - // quirk-free, original value. - existingValues[attributeName] = linkElement.data('cke-saved-' + attributeName) || attribute.nodeValue; - } - } - - // Prepare a save callback to be used upon saving the dialog. - var saveCallback = function (returnValues) { - editor.fire('saveSnapshot'); - - // Create a new link element if needed. - if (!linkElement && returnValues.attributes.href) { - var selection = editor.getSelection(); - var range = selection.getRanges(1)[0]; - - // Use link URL as text with a collapsed cursor. - if (range.collapsed) { - // Shorten mailto URLs to just the email address. - var text = new CKEDITOR.dom.text(returnValues.attributes.href.replace(/^mailto:/, ''), editor.document); - range.insertNode(text); - range.selectNodeContents(text); - } - - // Create the new link by applying a style to the new text. - var style = new CKEDITOR.style({element: 'a', attributes: returnValues.attributes}); - style.type = CKEDITOR.STYLE_INLINE; - style.applyToRange(range); - range.select(); - - // Set the link so individual properties may be set below. - linkElement = getSelectedLink(editor); - } - // Update the link properties. - else if (linkElement) { - for (var attrName in returnValues.attributes) { - if (returnValues.attributes.hasOwnProperty(attrName)) { - // Update the property if a value is specified. - if (returnValues.attributes[attrName].length > 0) { - var value = returnValues.attributes[attrName]; - linkElement.data('cke-saved-' + attrName, value); - linkElement.setAttribute(attrName, value); - } - // Delete the property if set to an empty string. - else { - linkElement.removeAttribute(attrName); - } - } - } - } - - // Save snapshot for undo support. - editor.fire('saveSnapshot'); - }; - // Drupal.t() will not work inside CKEditor plugins because CKEditor - // loads the JavaScript file instead of Drupal. Pull translated - // strings from the plugin settings that are translated server-side. - var dialogSettings = { - title: linkElement ? editor.config.linkit_dialogTitleAdd : editor.config.linkit_dialogTitleEdit, - dialogClass: 'editor-linkit-dialog' - }; - - // Open the dialog for the edit form. - Drupal.ckeditor.openDialog(editor, Drupal.url('linkit/dialog/linkit/' + editor.config.drupal.format), existingValues, saveCallback, dialogSettings); - } - }); - - // CTRL + L. - editor.setKeystroke(CKEDITOR.CTRL + 76, 'linkit'); - - // Add buttons. - if (editor.ui.addButton) { - editor.ui.addButton('Linkit', { - label: Drupal.t('Link'), - command: 'linkit', - icon: this.path + '/linkit.png' - }); - } - - editor.on('doubleclick', function (evt) { - var element = getSelectedLink(editor) || evt.data.element; - - if (!element.isReadOnly()) { - if (element.is('a')) { - editor.getSelection().selectElement(element); - editor.getCommand('linkit').exec(); - } - } - }); - - // If the "menu" plugin is loaded, register the menu items. - if (editor.addMenuItems) { - editor.addMenuItems({ - linkit: { - label: Drupal.t('Edit Link'), - command: 'linkit', - group: 'link', - order: 1 - } - }); - } - - // If the "contextmenu" plugin is loaded, register the listeners. - if (editor.contextMenu) { - editor.contextMenu.addListener(function (element, selection) { - if (!element || element.isReadOnly()) { - return null; - } - var anchor = getSelectedLink(editor); - if (!anchor) { - return null; - } - - var menu = {}; - if (anchor.getAttribute('href') && anchor.getChildCount()) { - menu = { - linkit: CKEDITOR.TRISTATE_OFF - }; - } - return menu; - }); - } - } - }); - - /** - * Get the surrounding link element of current selection. - * - * The following selection will all return the link element. - * - * @example - * li^nk - * [link] - * text[link] - * li[nk] - * [li]nk] - * [li]nk - * - * @param {CKEDITOR.editor} editor - * The CKEditor editor object - * - * @return {?HTMLElement} - * The selected link element, or null. - * - */ - function getSelectedLink(editor) { - var selection = editor.getSelection(); - var selectedElement = selection.getSelectedElement(); - if (selectedElement && selectedElement.is('a')) { - return selectedElement; - } - - var range = selection.getRanges(true)[0]; - - if (range) { - range.shrink(CKEDITOR.SHRINK_TEXT); - return editor.elementPath(range.getCommonAncestor()).contains('a', 1); - } - return null; - } - -})(jQuery, Drupal, drupalSettings, CKEDITOR); diff --git a/linkit.libraries.yml b/linkit.libraries.yml index ad835e5..6348cb6 100644 --- a/linkit.libraries.yml +++ b/linkit.libraries.yml @@ -26,14 +26,6 @@ linkit.autocomplete: - core/jquery.ui.autocomplete - core/underscore -linkit.attribute.title: - version: VERSION - js: - js/attribute/title.js: {} - dependencies: - - linkit/linkit.base - - linkit/linkit.autocomplete - linkit.imce: version: VERSION js: diff --git a/linkit.links.action.yml b/linkit.links.action.yml index b29f51f..8b5c1fa 100644 --- a/linkit.links.action.yml +++ b/linkit.links.action.yml @@ -9,10 +9,3 @@ linkit.matcher.add: title: 'Add matcher' appears_on: - linkit.matchers - -linkit.attribute.add: - route_name: linkit.attribute.add - title: 'Add attribute' - appears_on: - - linkit.attributes - diff --git a/linkit.links.task.yml b/linkit.links.task.yml index 671a9a5..39dde93 100644 --- a/linkit.links.task.yml +++ b/linkit.links.task.yml @@ -8,8 +8,3 @@ linkit.matchers: title: 'Manage matchers' base_route: entity.linkit_profile.edit_form weight: 5 -linkit.attributes: - route_name: linkit.attributes - title: 'Manage attributes' - base_route: entity.linkit_profile.edit_form - weight: 10 diff --git a/linkit.module b/linkit.module index 7765139..7997adf 100644 --- a/linkit.module +++ b/linkit.module @@ -23,6 +23,15 @@ function linkit_help($route_name, RouteMatchInterface $route_match) { } /** + * Implements hook_ckeditor_plugin_info_alter(). + */ +function linkit_ckeditor_plugin_info_alter(array &$plugins) { + if (isset($plugins['drupallink'])) { + $plugins['drupallink']['class'] = "Drupal\\linkit\\Plugin\\CKEditorPlugin\\LinkitDrupalLink"; + } +} + +/** * Implements hook_form_FORM_ID_alter() for editor_link_dialog. */ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_state, $form_id) { @@ -33,16 +42,11 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s /** @var \Drupal\Core\Entity\EntityStorageInterface $editorStorage */ $editorStorage = Drupal::service('entity.manager')->getStorage('editor'); - /** @var \Drupal\Core\Entity\EntityStorageInterface $linkitProfileStorage */ - $linkitProfileStorage = Drupal::service('entity.manager')->getStorage('linkit_profile'); /** @var \Drupal\editor\EditorInterface $editor */ $editor = $editorStorage->load($filter_format->id()); - $linkit_profile_id = $editor->getSettings()['plugins']['linkit']['linkit_profile']; - - /** @var \Drupal\linkit\ProfileInterface $linkitProfile */ - $linkitProfile = $linkitProfileStorage->load($linkit_profile_id); - + $linkit_profile_id = $editor->getSettings()['plugins']['drupallink']['linkit_profile']; + // Everything under the "attributes" key is merged directly into the // generated link tag's attributes. $form['attributes']['href'] = [ @@ -59,27 +63,6 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s // Add #submit callback that generates data-entity-type and data-entity-uuid // attributes from the href attribute when appropriate. array_unshift($form['#submit'], 'linkit_form_editor_link_dialog_submit'); - - if ($linkitProfile->getAttributes()->count()) { - $form['linkit_attributes'] = [ - '#type' => 'container', - '#title' => t('Attributes'), - '#weight' => '10', - ]; - - /** @var \Drupal\linkit\AttributeInterface $plugin */ - foreach ($linkitProfile->getAttributes() as $plugin) { - $plugin_name = $plugin->getHtmlName(); - - $default_value = isset($input[$plugin_name]) ? $input[$plugin_name] : ''; - $form['linkit_attributes'][$plugin_name] = $plugin->buildFormElement($default_value); - $form['linkit_attributes'][$plugin_name] += [ - '#parents' => [ - 'attributes', $plugin_name, - ], - ]; - } - } } /** diff --git a/linkit.routing.yml b/linkit.routing.yml index 035952c..b81eabd 100644 --- a/linkit.routing.yml +++ b/linkit.routing.yml @@ -29,37 +29,6 @@ entity.linkit_profile.delete_form: requirements: _permission: 'administer linkit profiles' -linkit.attributes: - path: '/admin/config/content/linkit/manage/{linkit_profile}/attributes' - defaults: - _form: '\Drupal\linkit\Form\Attribute\OverviewForm' - _title: 'Manage attributes' - requirements: - _permission: 'administer linkit profiles' - -linkit.attribute.add: - path: '/admin/config/content/linkit/manage/{linkit_profile}/attributes/add' - defaults: - _form: '\Drupal\linkit\Form\Attribute\AddForm' - _title: 'Add attribute' - requirements: - _permission: 'administer linkit profiles' - -linkit.attribute.delete: - path: '/admin/config/content/linkit/manage/{linkit_profile}/attributes/{plugin_instance_id}/delete' - defaults: - _form: '\Drupal\linkit\Form\Attribute\DeleteForm' - requirements: - _permission: 'administer linkit profiles' - -linkit.attribute.edit: - path: '/admin/config/content/linkit/manage/{linkit_profile}/attributes/{plugin_instance_id}' - defaults: - _form: '\Drupal\linkit\Form\Attribute\EditForm' - _title_callback: 'Drupal\linkit\Controller\LinkitController::attributeTitle' - requirements: - _permission: 'administer linkit profiles' - linkit.matchers: path: '/admin/config/content/linkit/manage/{linkit_profile}/matchers' defaults: @@ -91,16 +60,6 @@ linkit.matcher.edit: requirements: _permission: 'administer linkit profiles' -linkit.linkit_dialog: - path: '/linkit/dialog/linkit/{filter_format}' - defaults: - _form: '\Drupal\linkit\Form\LinkitEditorDialog' - _title: 'Add link' - requirements: - _entity_access: 'filter_format.use' - options: - _theme: ajax_base_page - linkit.autocomplete: path: '/linkit/autocomplete/{linkit_profile_id}' defaults: diff --git a/linkit.services.yml b/linkit.services.yml index 1deeb86..01eeef0 100644 --- a/linkit.services.yml +++ b/linkit.services.yml @@ -1,8 +1,4 @@ services: - plugin.manager.linkit.attribute: - class: Drupal\linkit\AttributeManager - parent: default_plugin_manager - plugin.manager.linkit.matcher: class: Drupal\linkit\MatcherManager parent: default_plugin_manager diff --git a/src/Annotation/Attribute.php b/src/Annotation/Attribute.php deleted file mode 100644 index d22b34b..0000000 --- a/src/Annotation/Attribute.php +++ /dev/null @@ -1,69 +0,0 @@ -setConfiguration($configuration); - } - - /** - * {@inheritdoc} - */ - public function getConfiguration() { - return [ - 'id' => $this->getPluginId(), - 'weight' => $this->weight, - 'settings' => $this->configuration, - ]; - } - - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) { - $configuration += [ - 'weight' => '0', - 'settings' => [], - ]; - $this->configuration = $configuration['settings'] + $this->defaultConfiguration(); - $this->weight = $configuration['weight']; - return $this; - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return []; - } - - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - return []; - } - - /** - * {@inheritdoc} - */ - public function getLabel() { - return $this->pluginDefinition['label']; - } - - /** - * {@inheritdoc} - */ - public function getHtmlName() { - return $this->pluginDefinition['html_name']; - } - - /** - * {@inheritdoc} - */ - public function getDescription() { - return $this->pluginDefinition['description']; - } - - /** - * {@inheritdoc} - */ - public function getWeight() { - return $this->weight; - } - - /** - * {@inheritdoc} - */ - public function setWeight($weight) { - $this->weight = $weight; - return $this; - } - -} diff --git a/src/AttributeCollection.php b/src/AttributeCollection.php deleted file mode 100644 index 3b4d88b..0000000 --- a/src/AttributeCollection.php +++ /dev/null @@ -1,46 +0,0 @@ -get($aID)->getWeight(); - $b_weight = $this->get($bID)->getWeight(); - if ($a_weight == $b_weight) { - return strnatcasecmp($this->get($aID)->getLabel(), $this->get($bID)->getLabel()); - } - - return ($a_weight < $b_weight) ? -1 : 1; - } - -} diff --git a/src/AttributeInterface.php b/src/AttributeInterface.php deleted file mode 100644 index d3e865b..0000000 --- a/src/AttributeInterface.php +++ /dev/null @@ -1,78 +0,0 @@ -<a> tag. - * - * @return string - * The attribute html name. - */ - public function getHtmlName(); - - /** - * Returns the weight of the attribute. - * - * @return int|string - * Either the integer weight of the attribute or an empty string. - */ - public function getWeight(); - - /** - * Sets the weight for this attribute. - * - * @param int $weight - * The weight for this attribute. - * - * @return $this - */ - public function setWeight($weight); - - /** - * The form element structure for this attribute to be used in the dialog. - * - * @param mixed $default_value - * The default value for the element. Used when editing an attribute in the - * dialog. - * - * @return array - * The form element. - */ - public function buildFormElement($default_value); - -} diff --git a/src/AttributeManager.php b/src/AttributeManager.php deleted file mode 100644 index 99d5a3b..0000000 --- a/src/AttributeManager.php +++ /dev/null @@ -1,29 +0,0 @@ -alterInfo('linkit_attribute'); - $this->setCacheBackend($cache_backend, 'linkit_attributes'); - } - -} diff --git a/src/ConfigurableAttributeBase.php b/src/ConfigurableAttributeBase.php deleted file mode 100644 index 14ba441..0000000 --- a/src/ConfigurableAttributeBase.php +++ /dev/null @@ -1,16 +0,0 @@ -t('Edit %label matcher', array('%label' => $matcher->getLabel())); } - /** - * Route title callback. - * - * @param \Drupal\linkit\ProfileInterface $linkit_profile - * The profile. - * @param string $plugin_instance_id - * The plugin instance id. - * - * @return string - * The title for the attribute edit form. - */ - public function attributeTitle(ProfileInterface $linkit_profile, $plugin_instance_id) { - /** @var \Drupal\linkit\AttributeInterface $attribute */ - $attribute = $linkit_profile->getAttribute($plugin_instance_id); - return $this->t('Edit %label attribute', array('%label' => $attribute->getLabel())); - } - } diff --git a/src/Entity/Profile.php b/src/Entity/Profile.php index 785ff63..156b8ec 100644 --- a/src/Entity/Profile.php +++ b/src/Entity/Profile.php @@ -9,7 +9,6 @@ namespace Drupal\linkit\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; -use Drupal\linkit\AttributeCollection; use Drupal\linkit\MatcherCollection; use Drupal\linkit\MatcherInterface; use Drupal\linkit\ProfileInterface; @@ -43,7 +42,6 @@ use Drupal\linkit\ProfileInterface; * "id", * "label", * "description", - * "attributes", * "matchers" * } * ) @@ -72,28 +70,6 @@ class Profile extends ConfigEntityBase implements ProfileInterface, EntityWithPl protected $description; /** - * Configured attribute for this profile. - * - * An associative array of attribute assigned to the profile, keyed by the - * attribute id of each attribute and using the properties: - * - id: The plugin ID of the attribute instance. - * - status: (optional) A Boolean indicating whether the attribute is enabled - * in the profile. Defaults to FALSE. - * - weight: (optional) The weight of the attribute in the profile. - * Defaults to 0. - * - * @var array - */ - protected $attributes = []; - - /** - * Holds the collection of attributes that are attached to this profile. - * - * @var \Drupal\linkit\AttributeCollection - */ - protected $attributeCollection; - - /** * Configured matchers for this profile. * * An associative array of matchers assigned to the profile, keyed by the @@ -133,50 +109,6 @@ class Profile extends ConfigEntityBase implements ProfileInterface, EntityWithPl /** * {@inheritdoc} */ - public function getAttribute($attribute_id) { - return $this->getAttributes()->get($attribute_id); - } - - /** - * {@inheritdoc} - */ - public function getAttributes() { - if (!$this->attributeCollection) { - $this->attributeCollection = new AttributeCollection($this->getAttributeManager(), $this->attributes); - $this->attributeCollection->sort(); - } - return $this->attributeCollection; - } - - /** - * {@inheritdoc} - */ - public function addAttribute(array $configuration) { - $this->getAttributes()->addInstanceId($configuration['id'], $configuration); - return $configuration['id']; - } - - /** - * {@inheritdoc} - */ - public function removeAttribute($attribute_id) { - unset($this->attributes[$attribute_id]); - $this->getAttributes()->removeInstanceId($attribute_id); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setAttributeConfig($attribute_id, array $configuration) { - $this->attributes[$attribute_id] = $configuration; - $this->getAttributes()->setInstanceConfiguration($attribute_id, $configuration); - return $this; - } - - /** - * {@inheritdoc} - */ public function getMatcher($instance_id) { return $this->getMatchers()->get($instance_id); } @@ -223,20 +155,9 @@ class Profile extends ConfigEntityBase implements ProfileInterface, EntityWithPl * {@inheritdoc} */ public function getPluginCollections() { - return array( - 'attributes' => $this->getAttributes(), + return [ 'matchers' => $this->getMatchers(), - ); - } - - /** - * Returns the attribute manager. - * - * @return \Drupal\Component\Plugin\PluginManagerInterface - * The attribute manager. - */ - protected function getAttributeManager() { - return \Drupal::service('plugin.manager.linkit.attribute'); + ]; } /** diff --git a/src/Form/Attribute/AddForm.php b/src/Form/Attribute/AddForm.php deleted file mode 100644 index 059ef51..0000000 --- a/src/Form/Attribute/AddForm.php +++ /dev/null @@ -1,166 +0,0 @@ -manager = $manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.linkit.attribute') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return "linkit_attribute_add_form"; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) { - $this->linkitProfile = $linkit_profile; - - $form['#attached']['library'][] = 'linkit/linkit.admin'; - $header = [ - 'label' => $this->t('Attributes'), - 'description' => $this->t('Description'), - ]; - - $form['plugin'] = [ - '#type' => 'tableselect', - '#header' => $header, - '#options' => $this->buildRows(), - '#empty' => $this->t('No attributes available.'), - '#multiple' => FALSE, - ]; - - $form['actions'] = ['#type' => 'actions']; - $form['actions']['submit'] = [ - '#type' => 'submit', - '#value' => $this->t('Save and continue'), - '#submit' => ['::submitForm'], - '#tableselect' => TRUE, - '#button_type' => 'primary', - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - if (empty($form_state->getValue('plugin'))) { - $form_state->setErrorByName('plugin', $this->t('No attribute selected.')); - } - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->cleanValues(); - - /** @var \Drupal\linkit\AttributeInterface $plugin */ - $plugin = $this->manager->createInstance($form_state->getValue('plugin')); - $plugin_id = $this->linkitProfile->addAttribute($plugin->getConfiguration()); - $this->linkitProfile->save(); - - $this->logger('linkit')->notice('Added %label attribute to the @profile profile.', [ - '%label' => $this->linkitProfile->getAttribute($plugin_id)->getLabel(), - '@profile' => $this->linkitProfile->label(), - ]); - - $is_configurable = $plugin instanceof ConfigurableAttributeInterface; - if ($is_configurable) { - $form_state->setRedirect('linkit.attribute.edit', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $plugin_id, - ]); - } - else { - drupal_set_message($this->t('Added %label attribute.', ['%label' => $plugin->getLabel()])); - - $form_state->setRedirect('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ]); - } - } - - /** - * Builds the table rows. - * - * Only attributes that is not already applied to the profile are shown. - * - * @return array - * An array of table rows. - */ - private function buildRows() { - $rows = []; - - $applied_plugins = $this->linkitProfile->getAttributes()->getConfiguration(); - $all_plugins = $this->manager->getDefinitions(); - uasort($all_plugins, function ($a, $b) { - return strnatcasecmp($a['label'], $b['label']); - }); - foreach (array_diff_key($all_plugins, $applied_plugins) as $definition) { - /** @var \Drupal\linkit\AttributeInterface $plugin */ - $plugin = $this->manager->createInstance($definition['id']); - - $row = [ - 'label' => (string) $plugin->getLabel(), - 'description' => (string) $plugin->getDescription(), - ]; - - $rows[$plugin->getPluginId()] = $row; - } - - return $rows; - } - -} diff --git a/src/Form/Attribute/DeleteForm.php b/src/Form/Attribute/DeleteForm.php deleted file mode 100644 index d31e44b..0000000 --- a/src/Form/Attribute/DeleteForm.php +++ /dev/null @@ -1,92 +0,0 @@ -t('Are you sure you want to delete the @plugin attribute from the %profile profile?', ['%profile' => $this->linkitProfile->label(), '@plugin' => $this->linkitAttribute->getLabel()]); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ]); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'linkit_attribute_delete_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) { - $this->linkitProfile = $linkit_profile; - - if (!$this->linkitProfile->getAttributes()->has($plugin_instance_id)) { - throw new NotFoundHttpException(); - } - - $this->linkitAttribute = $this->linkitProfile->getAttribute($plugin_instance_id); - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - if ($this->linkitProfile->getAttributes()->has($this->linkitAttribute->getPluginId())) { - $this->linkitProfile->removeAttribute($this->linkitAttribute->getPluginId()); - $this->linkitProfile->save(); - - drupal_set_message($this->t('The attribute %label has been deleted.', ['%label' => $this->linkitAttribute->getLabel()])); - $this->logger('linkit')->notice('The attribute %label has been deleted in the @profile profile.', [ - '%label' => $this->linkitAttribute->getLabel(), - '@profile' => $this->linkitProfile->label(), - ]); - } - - $form_state->setRedirect('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ]); - } - -} diff --git a/src/Form/Attribute/EditForm.php b/src/Form/Attribute/EditForm.php deleted file mode 100644 index 0b76601..0000000 --- a/src/Form/Attribute/EditForm.php +++ /dev/null @@ -1,96 +0,0 @@ -linkitProfile = $linkit_profile; - $this->linkitAttribute = $this->linkitProfile->getAttribute($plugin_instance_id); - $form['data'] = [ - '#tree' => true, - ]; - - $form['data'] += $this->linkitAttribute->buildConfigurationForm($form, $form_state); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => $this->t('Save changes'), - '#submit' => array('::submitForm'), - '#button_type' => 'primary', - ); - $form['actions']['delete'] = array( - '#type' => 'link', - '#title' => $this->t('Delete'), - '#url' => Url::fromRoute('linkit.attribute.delete', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $this->linkitAttribute->getPluginId(), - ]), - '#attributes' => [ - 'class' => ['button', 'button--danger'], - ], - ); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->cleanValues(); - $plugin_data = (new FormState())->setValues($form_state->getValue('data')); - $this->linkitAttribute->submitConfigurationForm($form, $plugin_data); - $this->linkitProfile->save(); - - drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->linkitAttribute->getLabel()))); - $this->logger('linkit')->notice('The attribute %label has been updated in the @profile profile.', [ - '%label' => $this->linkitAttribute->getLabel(), - '@profile' => $this->linkitProfile->label(), - ]); - - $form_state->setRedirect('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ]); - } - -} diff --git a/src/Form/Attribute/OverviewForm.php b/src/Form/Attribute/OverviewForm.php deleted file mode 100644 index 267dd61..0000000 --- a/src/Form/Attribute/OverviewForm.php +++ /dev/null @@ -1,156 +0,0 @@ -manager = $manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.linkit.attribute') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return "linkit_attribute_overview_form"; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) { - $this->linkitProfile = $linkit_profile; - - $form['plugins'] = [ - '#type' => 'table', - '#header' => [ - $this->t('Attribute'), - $this->t('Description'), - $this->t('Weight'), - $this->t('Operations'), - ], - '#empty' => $this->t('No attributes added.'), - '#tabledrag' => [ - [ - 'action' => 'order', - 'relationship' => 'sibling', - 'group' => 'plugin-order-weight', - ], - ], - ]; - - foreach ($this->linkitProfile->getAttributes() as $plugin) { - $key = $plugin->getPluginId(); - - $form['plugins'][$key]['#attributes']['class'][] = 'draggable'; - $form['plugins'][$key]['#weight'] = $plugin->getWeight(); - - $form['plugins'][$key]['label'] = [ - '#plain_text' => (string) $plugin->getLabel(), - ]; - - $form['plugins'][$key]['description'] = [ - '#plain_text' => (string) $plugin->getDescription(), - ]; - - $form['plugins'][$key]['weight'] = [ - '#type' => 'weight', - '#title' => t('Weight for @title', ['@title' => (string) $plugin->getLabel()]), - '#title_display' => 'invisible', - '#default_value' => $plugin->getWeight(), - '#attributes' => ['class' => ['plugin-order-weight']], - ]; - - $form['plugins'][$key]['operations'] = [ - '#type' => 'operations', - '#links' => [], - ]; - - $is_configurable = $plugin instanceof ConfigurableAttributeInterface; - if ($is_configurable) { - $form['plugins'][$key]['operations']['#links']['edit'] = [ - 'title' => t('Edit'), - 'url' => Url::fromRoute('linkit.attribute.edit', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $key, - ]), - ]; - } - - $form['plugins'][$key]['operations']['#links']['delete'] = [ - 'title' => t('Delete'), - 'url' => Url::fromRoute('linkit.attribute.delete', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $key, - ]), - ]; - } - - $form['actions'] = ['#type' => 'actions']; - $form['actions']['submit'] = [ - '#type' => 'submit', - '#value' => $this->t('Save'), - '#button_type' => 'primary', - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - foreach ($form_state->getValue('plugins') as $id => $plugin_data) { - if ($this->linkitProfile->getAttributes()->has($id)) { - $this->linkitProfile->getAttribute($id)->setWeight($plugin_data['weight']); - } - } - $this->linkitProfile->save(); - } - -} diff --git a/src/Form/LinkitEditorDialog.php b/src/Form/LinkitEditorDialog.php deleted file mode 100644 index 8f3b8f5..0000000 --- a/src/Form/LinkitEditorDialog.php +++ /dev/null @@ -1,207 +0,0 @@ -editorStorage = $editor_storage; - $this->linkitProfileStorage = $linkit_profile_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager')->getStorage('editor'), - $container->get('entity.manager')->getStorage('linkit_profile') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'linkit_editor_dialog_form'; - } - - /** - * {@inheritdoc} - * - * @param \Drupal\filter\Entity\FilterFormat $filter_format - * The filter format for which this dialog corresponds. - */ - public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) { - // The default values are set directly from \Drupal::request()->request, - // provided by the editor plugin opening the dialog. - $user_input = $form_state->getUserInput(); - $input = isset($user_input['editor_object']) ? $user_input['editor_object'] : []; - - /** @var \Drupal\editor\EditorInterface $editor */ - $editor = $this->editorStorage->load($filter_format->id()); - $linkit_profile_id = $editor->getSettings()['plugins']['linkit']['linkit_profile']; - $this->linkitProfile = $this->linkitProfileStorage->load($linkit_profile_id); - - $form['#tree'] = TRUE; - $form['#attached']['library'][] = 'editor/drupal.editor.dialog'; - $form['#prefix'] = '