Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / Form / Attribute / EditForm.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Form\Attribute\EditForm.
6  */
7
8 namespace Drupal\linkit\Form\Attribute;
9
10 use Drupal\Core\Form\FormBase;
11 use Drupal\Core\Form\FormState;
12 use Drupal\Core\Form\FormStateInterface;
13 use Drupal\Core\Url;
14 use Drupal\linkit\ProfileInterface;
15
16 /**
17  *  Provides an edit form for attributes.
18  */
19 class EditForm extends FormBase {
20
21   /**
22    * The profiles to which the attributes will be applied.
23    *
24    * @var \Drupal\linkit\ProfileInterface
25    */
26   protected $linkitProfile;
27
28   /**
29    * The attribute to edit.
30    *
31    * @var \Drupal\linkit\ConfigurableAttributeInterface
32    */
33   protected $linkitAttribute;
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getFormId() {
39     return 'linkit_attribute_edit_form';
40   }
41
42   /**
43    * {@inheritdoc}
44    */
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);
48     $form['data'] = [
49       '#tree' => true,
50     ];
51
52     $form['data'] += $this->linkitAttribute->buildConfigurationForm($form, $form_state);
53
54     $form['actions'] = array('#type' => 'actions');
55     $form['actions']['submit'] = array(
56       '#type' => 'submit',
57       '#value' => $this->t('Save changes'),
58       '#submit' => array('::submitForm'),
59       '#button_type' => 'primary',
60     );
61     $form['actions']['delete'] = array(
62       '#type' => 'link',
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(),
67       ]),
68       '#attributes' => [
69         'class' => ['button', 'button--danger'],
70       ],
71     );
72
73     return $form;
74   }
75
76   /**
77    * {@inheritdoc}
78    */
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();
84
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(),
89     ]);
90
91     $form_state->setRedirect('linkit.attributes', [
92       'linkit_profile' => $this->linkitProfile->id(),
93     ]);
94   }
95
96 }