5 * Contains \Drupal\linkit\Form\Profile\FormBase.
8 namespace Drupal\linkit\Form\Profile;
10 use Drupal\Core\Entity\EntityForm;
11 use Drupal\Core\Form\FormStateInterface;
14 * Base form for profile add and edit forms.
16 abstract class FormBase extends EntityForm {
19 * The entity being used by this form.
21 * @var \Drupal\linkit\ProfileInterface
28 public function form(array $form, FormStateInterface $form_state) {
30 '#type' => 'textfield',
31 '#title' => $this->t('Profile Name'),
32 '#default_value' => $this->entity->label(),
33 '#description' => $this->t('The human-readable name of this profile. This name must be unique.'),
39 '#type' => 'machine_name',
40 '#default_value' => $this->entity->id(),
42 'exists' => ['\Drupal\linkit\Entity\Profile', 'load']
44 '#disabled' => !$this->entity->isNew(),
47 $form['description'] = [
48 '#type' => 'textarea',
49 '#title' => $this->t('Description'),
50 '#default_value' => $this->entity->getDescription(),
51 '#description' => $this->t('The text will be displayed on the <em>profile collection</em> page.'),
54 $form['additional_settings'] = array(
55 '#type' => 'vertical_tabs',
59 return parent::form($form, $form_state);
65 public function save(array $form, FormStateInterface $form_state) {
66 $linkit_profile = $this->entity;
68 // Prevent leading and trailing spaces in linkit profile labels.
69 $linkit_profile->set('label', trim($linkit_profile->label()));
71 $status = $linkit_profile->save();
72 $edit_link = $this->entity->link($this->t('Edit'));
75 drupal_set_message($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()]));
76 $this->logger('linkit')->notice('Created new profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
77 $form_state->setRedirect('linkit.matchers', [
78 'linkit_profile' => $linkit_profile->id(),
83 drupal_set_message($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()]));
84 $this->logger('linkit')->notice('Updated profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
85 $form_state->setRedirectUrl($linkit_profile->urlInfo('edit-form'));