Esempio n. 1
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
    $this->linkitProfile = $linkit_profile;
    $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);

    $form += $this->linkitMatcher->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.matcher.delete', [
        'linkit_profile' => $this->linkitProfile->id(),
        'plugin_instance_id' => $this->linkitMatcher->getUuid(),
      ]),
      '#attributes' => [
        'class' => ['button', 'button--danger'],
      ],
    );

    return $form;
  }
Esempio n. 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->getMatchers()->has($plugin_instance_id)) {
      throw new NotFoundHttpException();
    }

    $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);
    return parent::buildForm($form, $form_state);
  }
Esempio n. 3
0
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->cleanValues();

    /** @var \Drupal\linkit\MatcherInterface $plugin */
    $plugin = $this->manager->createInstance($form_state->getValue('plugin'));

    $plugin_uuid = $this->linkitProfile->addMatcher($plugin->getConfiguration());
    $this->linkitProfile->save();

    $this->logger('linkit')->notice('Added %label matcher to the @profile profile.', [
      '%label' => $this->linkitProfile->getMatcher($plugin_uuid)->getLabel(),
      '@profile' => $this->linkitProfile->label(),
    ]);

    $is_configurable = $plugin instanceof ConfigurableMatcherInterface;
    if ($is_configurable) {
      $form_state->setRedirect('linkit.matcher.edit', [
        'linkit_profile' => $this->linkitProfile->id(),
        'plugin_instance_id' => $plugin_uuid,
      ]);
    }
    else {
      drupal_set_message($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()]));

      $form_state->setRedirect('linkit.matchers', [
        'linkit_profile' => $this->linkitProfile->id(),
      ]);
    }
  }
Esempio n. 4
0
  /**
   * Test adding a configurable attribute to a profile.
   */
  function testAddConfigurable() {
    $this->drupalGet(Url::fromRoute('linkit.matcher.add', [
      'linkit_profile' => $this->linkitProfile->id(),
    ]));

    $edit = array();
    $edit['plugin'] = 'configurable_dummy_matcher';
    $this->drupalPostForm(NULL, $edit, t('Save and continue'));

    // Load the saved profile.
    $this->linkitProfile = Profile::load($this->linkitProfile->id());

    $matcher_ids = $this->linkitProfile->getMatchers()->getInstanceIds();
    /** @var \Drupal\linkit\MatcherInterface $plugin */
    $plugin = $this->linkitProfile->getMatcher(current($matcher_ids));

    $this->assertUrl(Url::fromRoute('linkit.matcher.edit', [
      'linkit_profile' => $this->linkitProfile->id(),
      'plugin_instance_id' => $plugin->getUuid(),
    ]));

    $this->drupalGet(Url::fromRoute('linkit.matchers', [
      'linkit_profile' => $this->linkitProfile->id(),
    ]));

    $this->assertNoText(t('No matchers added.'));
  }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state) {
   foreach ($form_state->getValue('plugins') as $id => $plugin_data) {
     if ($this->linkitProfile->getMatchers()->has($id)) {
       $this->linkitProfile->getMatcher($id)->setWeight($plugin_data['weight']);
     }
   }
   $this->linkitProfile->save();
 }
Esempio n. 6
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 matcher edit form.
  */
 public function matcherTitle(ProfileInterface $linkit_profile, $plugin_instance_id) {
   /** @var \Drupal\linkit\MatcherInterface $matcher */
   $matcher = $linkit_profile->getMatcher($plugin_instance_id);
   return $this->t('Edit %label matcher', array('%label' => $matcher->getLabel()));
 }