5 * Contains \Drupal\linkit\Form\Attribute\EditForm.
8 namespace Drupal\linkit\Form\Attribute;
10 use Drupal\Core\Form\FormBase;
11 use Drupal\Core\Form\FormState;
12 use Drupal\Core\Form\FormStateInterface;
14 use Drupal\linkit\ProfileInterface;
17 * Provides an edit form for attributes.
19 class EditForm extends FormBase {
22 * The profiles to which the attributes will be applied.
24 * @var \Drupal\linkit\ProfileInterface
26 protected $linkitProfile;
29 * The attribute to edit.
31 * @var \Drupal\linkit\ConfigurableAttributeInterface
33 protected $linkitAttribute;
38 public function getFormId() {
39 return 'linkit_attribute_edit_form';
45 public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
46 $this->linkitProfile = $linkit_profile;
47 $this->linkitAttribute = $this->linkitProfile->getAttribute($plugin_instance_id);
52 $form['data'] += $this->linkitAttribute->buildConfigurationForm($form, $form_state);
54 $form['actions'] = array('#type' => 'actions');
55 $form['actions']['submit'] = array(
57 '#value' => $this->t('Save changes'),
58 '#submit' => array('::submitForm'),
59 '#button_type' => 'primary',
61 $form['actions']['delete'] = array(
63 '#title' => $this->t('Delete'),
64 '#url' => Url::fromRoute('linkit.attribute.delete', [
65 'linkit_profile' => $this->linkitProfile->id(),
66 'plugin_instance_id' => $this->linkitAttribute->getPluginId(),
69 'class' => ['button', 'button--danger'],
79 public function submitForm(array &$form, FormStateInterface $form_state) {
80 $form_state->cleanValues();
81 $plugin_data = (new FormState())->setValues($form_state->getValue('data'));
82 $this->linkitAttribute->submitConfigurationForm($form, $plugin_data);
83 $this->linkitProfile->save();
85 drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->linkitAttribute->getLabel())));
86 $this->logger('linkit')->notice('The attribute %label has been updated in the @profile profile.', [
87 '%label' => $this->linkitAttribute->getLabel(),
88 '@profile' => $this->linkitProfile->label(),
91 $form_state->setRedirect('linkit.attributes', [
92 'linkit_profile' => $this->linkitProfile->id(),