예제 #1
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
    $this->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;
  }
예제 #2
0
  /**
   * {@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);
  }
예제 #3
0
  /**
   * {@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(),
      ]);
    }
  }
예제 #4
0
 /**
  * {@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();
 }
예제 #5
0
 /**
  * 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()));
 }