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'] = '
'; - $form['#suffix'] = '
'; - - // Everything under the "attributes" key is merged directly into the - // generated link tag's attributes. - $form['attributes']['href'] = [ - '#title' => $this->t('Link'), - '#type' => 'linkit', - '#default_value' => isset($input['href']) ? $input['href'] : '', - '#description' => $this->t('Start typing to find content or paste a URL.'), - '#autocomplete_route_name' => 'linkit.autocomplete', - '#autocomplete_route_parameters' => [ - 'linkit_profile_id' => $linkit_profile_id - ], - '#weight' => 0, - ]; - - $this->addAttributes($form, $form_state, $this->linkitProfile->getAttributes(), $input); - - $form['actions'] = [ - '#type' => 'actions', - ]; - - $form['actions']['save_modal'] = [ - '#type' => 'submit', - '#value' => $this->t('Save'), - '#submit' => [], - '#ajax' => [ - 'callback' => '::submitForm', - 'event' => 'click', - ], - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - $attributes = array_filter($form_state->getValue('attributes')); - $form_state->setValue('attributes', $attributes); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $response = new AjaxResponse(); - - if ($form_state->getErrors()) { - unset($form['#prefix'], $form['#suffix']); - $form['status_messages'] = [ - '#type' => 'status_messages', - '#weight' => -10, - ]; - $response->addCommand(new HtmlCommand('#linkit-editor-dialog-form', $form)); - } - else { - $response->addCommand(new EditorDialogSave($form_state->getValues())); - $response->addCommand(new CloseModalDialogCommand()); - } - - return $response; - } - - /** - * Adds the attributes enabled on the current profile. - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - * @param AttributeCollection $attributes - * A collection of attributes for the current profile. - * @param array $input - * An array with the attribute values from the editor. - */ - private function addAttributes(array &$form, FormStateInterface &$form_state, AttributeCollection $attributes, array $input) { - if ($attributes->count()) { - $form['linkit_attributes'] = [ - '#type' => 'container', - '#title' => $this->t('Attributes'), - '#weight' => '10', - ]; - - /** @var \Drupal\linkit\AttributeInterface $plugin */ - foreach ($attributes 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, - ], - ]; - } - } - } - - /** - * Gets the linkit profile entity. - * - * @return \Drupal\linkit\ProfileInterface - * The current linkit profile used by this form. - */ - public function getLinkitProfile() { - return $this->linkitProfile; - } - -} diff --git a/src/Plugin/CKEditorPlugin/Linkit.php b/src/Plugin/CKEditorPlugin/Linkit.php deleted file mode 100644 index 54056a5..0000000 --- a/src/Plugin/CKEditorPlugin/Linkit.php +++ /dev/null @@ -1,123 +0,0 @@ -linkitProfileStorage = $linkit_profile_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity.manager')->getStorage('linkit_profile') - ); - } - - /** - * {@inheritdoc} - */ - public function getFile() { - return drupal_get_path('module', 'linkit') . '/js/plugins/linkit/plugin.js'; - } - - /** - * {@inheritdoc} - */ - public function getConfig(Editor $editor) { - return array( - 'linkit_dialogTitleAdd' => t('Add link'), - 'linkit_dialogTitleEdit' => t('Edit link'), - ); - } - - /** - * {@inheritdoc} - */ - public function getButtons() { - return array( - 'Linkit' => array( - 'label' => t('Linkit'), - 'image' => drupal_get_path('module', 'linkit') . '/js/plugins/linkit/linkit.png', - ), - ); - } - - /** - * {@inheritdoc} - */ - public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) { - $settings = $editor->getSettings(); - - $all_profiles = $this->linkitProfileStorage->loadMultiple(); - - $options = array(); - foreach ($all_profiles as $profile) { - $options[$profile->id()] = $profile->label(); - } - - $form['linkit_profile'] = array( - '#type' => 'select', - '#title' => t('Select a linkit profile'), - '#options' => $options, - '#default_value' => isset($settings['plugins']['linkit']) ? $settings['plugins']['linkit'] : '', - '#empty_option' => $this->t('- Select profile -'), - '#description' => $this->t('Select the linkit profile you wish to use with this text format.'), - '#element_validate' => array( - array($this, 'validateLinkitProfileSelection'), - ), - ); - - return $form; - } - - /** - * #element_validate handler for the "linkit_profile" element in settingsForm(). - */ - public function validateLinkitProfileSelection(array $element, FormStateInterface $form_state) { - $toolbar_buttons = $form_state->getValue(array('editor', 'settings', 'toolbar', 'button_groups')); - if (strpos($toolbar_buttons, '"Linkit"') !== FALSE && empty($element['#value'])) { - $form_state->setError($element, t('Please select the linkit profile you wish to use.')); - } - } - -} diff --git a/src/Plugin/CKEditorPlugin/LinkitDrupalLink.php b/src/Plugin/CKEditorPlugin/LinkitDrupalLink.php new file mode 100644 index 0000000..c32cc12 --- /dev/null +++ b/src/Plugin/CKEditorPlugin/LinkitDrupalLink.php @@ -0,0 +1,87 @@ +linkitProfileStorage = $linkit_profile_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager')->getStorage('linkit_profile') + ); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) { + $settings = $editor->getSettings(); + + $all_profiles = $this->linkitProfileStorage->loadMultiple(); + + $options = array(); + foreach ($all_profiles as $profile) { + $options[$profile->id()] = $profile->label(); + } + + $form['linkit_profile'] = array( + '#type' => 'select', + '#title' => t('Linkit profile'), + '#options' => $options, + '#default_value' => isset($settings['plugins']['drupallink']['linkit_profile']) ? $settings['plugins']['drupallink']['linkit_profile'] : '', + '#empty_option' => $this->t('- Select -'), + '#description' => $this->t('Select the Linkit profile you wish to use with this text format.'), + '#element_validate' => array( + array($this, 'validateLinkitProfileSelection'), + ), + ); + + return $form; + } + + /** + * #element_validate handler for the "linkit_profile" element in settingsForm(). + */ + public function validateLinkitProfileSelection(array $element, FormStateInterface $form_state) { + $toolbar_buttons = $form_state->getValue(array('editor', 'settings', 'toolbar', 'button_groups')); + if (strpos($toolbar_buttons, '"Linkit"') !== FALSE && empty($element['#value'])) { + $form_state->setError($element, t('Please select the linkit profile you wish to use.')); + } + } +} \ No newline at end of file diff --git a/src/Plugin/Linkit/Attribute/Accesskey.php b/src/Plugin/Linkit/Attribute/Accesskey.php deleted file mode 100644 index e0a609f..0000000 --- a/src/Plugin/Linkit/Attribute/Accesskey.php +++ /dev/null @@ -1,38 +0,0 @@ - 'textfield', - '#title' => t('Accesskey'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - '#placeholder' => t('The "accesskey" attribute value'), - ]; - } - -} diff --git a/src/Plugin/Linkit/Attribute/Clazz.php b/src/Plugin/Linkit/Attribute/Clazz.php deleted file mode 100644 index 03787e7..0000000 --- a/src/Plugin/Linkit/Attribute/Clazz.php +++ /dev/null @@ -1,41 +0,0 @@ - 'textfield', -// '#title' => t('Class'), -// '#maxlength' => 255, -// '#size' => 40, -// ]; -// } -// -//} diff --git a/src/Plugin/Linkit/Attribute/Id.php b/src/Plugin/Linkit/Attribute/Id.php deleted file mode 100644 index 817b1ba..0000000 --- a/src/Plugin/Linkit/Attribute/Id.php +++ /dev/null @@ -1,38 +0,0 @@ - 'textfield', - '#title' => t('Id'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - '#placeholder' => t('The "id" attribute value'), - ]; - } - -} diff --git a/src/Plugin/Linkit/Attribute/Relationship.php b/src/Plugin/Linkit/Attribute/Relationship.php deleted file mode 100644 index 0c32867..0000000 --- a/src/Plugin/Linkit/Attribute/Relationship.php +++ /dev/null @@ -1,38 +0,0 @@ - 'textfield', - '#title' => t('Relationship'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - '#placeholder' => t('The "rel" attribute value'), - ]; - } - -} diff --git a/src/Plugin/Linkit/Attribute/Target.php b/src/Plugin/Linkit/Attribute/Target.php deleted file mode 100644 index ce48337..0000000 --- a/src/Plugin/Linkit/Attribute/Target.php +++ /dev/null @@ -1,96 +0,0 @@ -configuration['widget_type']) { - case self::SELECT_LIST: - return [ - '#type' => 'select', - '#title' => t('Target'), - '#options' => [ - '' => '', - '_blank' => t('New window (_blank)'), - '_top' => t('Top window (_top)'), - '_self' => t('Same window (_self)'), - '_parent' => t('Parent window (_parent)') - ], - '#default_value' => $default_value, - ]; - case self::SIMPLE_CHECKBOX: - return [ - '#type' => 'checkbox', - '#title' => t('Open in new window'), - '#default_value' => $default_value, - '#return_value' => '_blank', - ]; - } - - return []; - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return parent::defaultConfiguration() + [ - 'widget_type' => self::SIMPLE_CHECKBOX, - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form['widget_type'] = [ - '#type' => 'radios', - '#title' => $this->t('Widget type'), - '#default_value' => $this->configuration['widget_type'], - '#options' => [ - self::SELECT_LIST => $this->t('Selectlist with predefined targets.'), - self::SIMPLE_CHECKBOX => $this->t('Simple checkbox to allow links to be opened in a new browser window or tab.'), - ], - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['widget_type'] = $form_state->getValue('widget_type'); - } - -} diff --git a/src/Plugin/Linkit/Attribute/Title.php b/src/Plugin/Linkit/Attribute/Title.php deleted file mode 100644 index 6cd8f3e..0000000 --- a/src/Plugin/Linkit/Attribute/Title.php +++ /dev/null @@ -1,82 +0,0 @@ - 'textfield', - '#title' => t('Title'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - '#placeholder' => t('The "title" attribute value'), - ]; - - if ($this->configuration['automatic_title']) { - $element['#attached']['library'][] = 'linkit/linkit.attribute.title'; - $element['#placeholder'] = t('The "title" attribute value (auto populated)'); - } - - return $element; - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return parent::defaultConfiguration() + [ - 'automatic_title' => FALSE, - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form['automatic_title'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Automatically populate title'), - '#default_value' => $this->configuration['automatic_title'], - '#description' => $this->t('Automatically populate the title attribute with the title from the match selection.'), - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['automatic_title'] = $form_state->getValue('automatic_title'); - } - -} diff --git a/src/ProfileInterface.php b/src/ProfileInterface.php index fae8275..2931604 100644 --- a/src/ProfileInterface.php +++ b/src/ProfileInterface.php @@ -33,58 +33,6 @@ interface ProfileInterface extends ConfigEntityInterface { public function setDescription($description); /** - * Returns a specific attribute. - * - * @param string $attribute_id - * The attribute ID. - * - * @return \Drupal\linkit\AttributeInterface - * The attribute object. - */ - public function getAttribute($attribute_id); - - /** - * Returns the attributes for this profile. - * - * @return \Drupal\linkit\AttributeCollection|\Drupal\linkit\AttributeInterface[] - * The attribute collection. - */ - public function getAttributes(); - - /** - * Adds an attribute to this profile. - * - * @param array $configuration - * An array of attribute configuration. - * - * @return String - * The ID of the attribute. - */ - public function addAttribute(array $configuration); - - /** - * Removes an attribute from this profile. - * - * @param string $attribute_id - * The attribute ID. - * - * @return $this - */ - public function removeAttribute($attribute_id); - - /** - * Sets the configuration for an attribute instance. - * - * @param string $attribute_id - * The ID of the attribute to set the configuration for. - * @param array $configuration - * The attribute configuration to set. - * - * @return $this - */ - public function setAttributeConfig($attribute_id, array $configuration); - - /** * Returns a specific matcher. * * @param string $instance_id diff --git a/src/ProfileListBuilder.php b/src/ProfileListBuilder.php index 562cd4a..ac690c5 100644 --- a/src/ProfileListBuilder.php +++ b/src/ProfileListBuilder.php @@ -59,14 +59,6 @@ class ProfileListBuilder extends ConfigEntityListBuilder { ]), ]; - $operations['attributes'] = [ - 'title' => t('Manage attributes'), - 'weight' => 20, - 'url' => Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $entity->id() - ]), - ]; - return $operations; } diff --git a/src/Tests/AttributeCrudTest.php b/src/Tests/AttributeCrudTest.php deleted file mode 100644 index 5132ff5..0000000 --- a/src/Tests/AttributeCrudTest.php +++ /dev/null @@ -1,160 +0,0 @@ -manager = $this->container->get('plugin.manager.linkit.attribute'); - - $this->linkitProfile = $this->createProfile(); - $this->drupalLogin($this->adminUser); - } - - /** - * Test the overview page. - */ - function testOverview() { - $this->drupalGet(Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - $this->assertText(t('No attributes added.')); - - $this->assertLinkByHref(Url::fromRoute('linkit.attribute.add', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])->toString()); - } - - /** - * Test adding an attribute to a profile. - */ - function testAdd() { - $this->drupalGet(Url::fromRoute('linkit.attribute.add', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - - $this->assertEqual(count($this->manager->getDefinitions()), count($this->xpath('//input[@type="radio"]')), 'All attributes are available.'); - - $edit = array(); - $edit['plugin'] = 'dummy_attribute'; - $this->drupalPostForm(NULL, $edit, t('Save and continue')); - - $this->assertUrl(Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - - $this->assertEqual(1, count($this->xpath('//table/tbody/tr')), 'Attribute added.'); - $this->assertNoText(t('No attributes added.')); - } - - /** - * Test adding a configurable attribute to a profile. - */ - function testAddConfigurable() { - $this->drupalGet(Url::fromRoute('linkit.attribute.add', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - - $this->assertEqual(count($this->manager->getDefinitions()), count($this->xpath('//input[@type="radio"]')), 'All attributes are available.'); - - $edit = array(); - $edit['plugin'] = 'configurable_dummy_attribute'; - $this->drupalPostForm(NULL, $edit, t('Save and continue')); - - $this->assertUrl(Url::fromRoute('linkit.attribute.edit', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => 'configurable_dummy_attribute', - ])); - - $this->drupalGet(Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - - $this->assertEqual(1, count($this->xpath('//table/tbody/tr')), 'Attribute added.'); - $this->assertNoText(t('No attributes added.')); - - $plugin_url = Url::fromRoute('linkit.attribute.edit', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => 'configurable_dummy_attribute', - ]); - - $this->assertLinkByHref($plugin_url->toString()); - } - - /** - * Test delete an attribute from a profile. - */ - function testDelete() { - /** @var \Drupal\linkit\AttributeInterface $plugin */ - $plugin = $this->manager->createInstance('dummy_attribute'); - - $this->linkitProfile->addAttribute($plugin->getConfiguration()); - $this->linkitProfile->save(); - - // Try delete an attribute that is not attached to the profile. - $this->drupalGet(Url::fromRoute('linkit.attribute.delete', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => 'doesntexists' - ])); - $this->assertResponse('404'); - - // Go to the delete page, but press cancel. - $this->drupalGet(Url::fromRoute('linkit.attribute.delete', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $plugin->getPluginId(), - ])); - $this->clickLink(t('Cancel')); - $this->assertUrl(Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - - // Delete the attribute from the profile. - $this->drupalGet(Url::fromRoute('linkit.attribute.delete', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => 'dummy_attribute', - ])); - - $this->drupalPostForm(NULL, [], t('Confirm')); - $this->assertRaw(t('The attribute %plugin has been deleted.', ['%plugin' => $plugin->getLabel()])); - $this->assertUrl(Url::fromRoute('linkit.attributes', [ - 'linkit_profile' => $this->linkitProfile->id(), - ])); - $this->assertText(t('No attributes added.')); - - /** @var \Drupal\linkit\Entity\Profile $updated_profile */ - $updated_profile = Profile::load($this->linkitProfile->id()); - $this->assertFalse($updated_profile->getAttributes()->has($plugin->getPluginId()), 'The attribute is deleted from the profile'); - } - -} diff --git a/src/Tests/Controllers/LinkitControllerTest.php b/src/Tests/Controllers/LinkitControllerTest.php index f7acbe8..b4ea4c0 100644 --- a/src/Tests/Controllers/LinkitControllerTest.php +++ b/src/Tests/Controllers/LinkitControllerTest.php @@ -63,21 +63,4 @@ class LinkitControllerTest extends LinkitTestBase { $this->assertText('Edit ' . $plugin->getLabel() . ' matcher'); } - - /** - * Tests the attribute route title callback. - */ - function testAttributeTitle() { - /** @var \Drupal\linkit\AttributeInterface $plugin */ - $plugin = $this->container->get('plugin.manager.linkit.attribute')->createInstance('configurable_dummy_attribute'); - $this->linkitProfile->addAttribute($plugin->getConfiguration()); - $this->linkitProfile->save(); - - $this->drupalGet(Url::fromRoute('linkit.attribute.edit', [ - 'linkit_profile' => $this->linkitProfile->id(), - 'plugin_instance_id' => $plugin->getPluginId(), - ])); - $this->assertText('Edit ' . $plugin->getLabel() . ' attribute'); - } - } diff --git a/tests/linkit_test/config/schema/linkit_test.schema.yml b/tests/linkit_test/config/schema/linkit_test.schema.yml index 2e78ae5..ce29e8f 100644 --- a/tests/linkit_test/config/schema/linkit_test.schema.yml +++ b/tests/linkit_test/config/schema/linkit_test.schema.yml @@ -1,13 +1,5 @@ # Schema for the configuration files of the Linkit test module. - -# Plugin \Drupal\linkit_test\Plugin\Linkit\Attribute\ConfigurableDummyAttribute -linkit.attribute.configurable_dummy_attribute: - type: linkit.attribute - mapping: - dummy_setting: - type: boolean - # Plugin \Drupal\linkit_test\Plugin\Linkit\Matcher\ConfigurableDummyMatcher linkit.matcher.configurable_dummy_matcher: type: linkit.matcher diff --git a/tests/linkit_test/linkit_test.module b/tests/linkit_test/linkit_test.module index 178e46d..e2b2c05 100644 --- a/tests/linkit_test/linkit_test.module +++ b/tests/linkit_test/linkit_test.module @@ -4,13 +4,3 @@ * @file * Support module for Linkit testing. */ - - -/** - * Implements hook_linkit_attribute_alter(). - */ -function linkit_test_linkit_attribute_alter(&$linkit_attribute_info) { - if (isset($linkit_attribute_info['dummyattribute'])) { - $linkit_attribute_info['dummyattribute']['description'] = t('Altered dummy description'); - } -} diff --git a/tests/linkit_test/src/Plugin/Linkit/Attribute/ConfigurableDummyAttribute.php b/tests/linkit_test/src/Plugin/Linkit/Attribute/ConfigurableDummyAttribute.php deleted file mode 100644 index 7dde958..0000000 --- a/tests/linkit_test/src/Plugin/Linkit/Attribute/ConfigurableDummyAttribute.php +++ /dev/null @@ -1,73 +0,0 @@ - 'textfield', - '#title' => t('DummyAttribute'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - ]; - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return parent::defaultConfiguration() + [ - 'dummy_setting' => FALSE, - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form['dummy_setting'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Dummy setting'), - '#default_value' => $this->configuration['dummy_setting'], - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['dummy_setting'] = $form_state->getValue('dummy_setting'); - } - -} diff --git a/tests/linkit_test/src/Plugin/Linkit/Attribute/DummyAttribute.php b/tests/linkit_test/src/Plugin/Linkit/Attribute/DummyAttribute.php deleted file mode 100644 index 8258167..0000000 --- a/tests/linkit_test/src/Plugin/Linkit/Attribute/DummyAttribute.php +++ /dev/null @@ -1,37 +0,0 @@ - 'textfield', - '#title' => t('DummyAttribute'), - '#default_value' => $default_value, - '#maxlength' => 255, - '#size' => 40, - ]; - } - -}