/** * Cancels the editing of the index's fields. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ public function cancel(array &$form, FormStateInterface $form_state) { if ($this->entity instanceof UnsavedConfigurationInterface && $this->entity->hasChanges()) { $this->entity->discardChanges(); } $form_state->setRedirectUrl($this->entity->toUrl('canonical')); }
/** * Removes a field from a search index. * * @param \Drupal\search_api\IndexInterface $search_api_index * The search index. * @param string $field_id * The ID of the field to remove. * * @return \Symfony\Component\HttpFoundation\Response * The response to send to the browser. * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * Thrown when the field was not found. */ public function removeField(IndexInterface $search_api_index, $field_id) { $fields = $search_api_index->getFields(); if (isset($fields[$field_id])) { try { $search_api_index->removeField($field_id); $search_api_index->save(); } catch (SearchApiException $e) { $args['%field'] = $fields[$field_id]->getLabel(); drupal_set_message($this->t('The field %field is locked and cannot be removed.', $args), 'error'); } } else { throw new NotFoundHttpException(); } // Redirect to the index's "View" page. $url = $search_api_index->toUrl('fields'); return $this->redirect($url->getRouteName(), $url->getRouteParameters()); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { return array('done' => array('#type' => 'link', '#title' => $this->t('Done'), '#url' => $this->entity->toUrl('fields'), '#attributes' => array('class' => array('button')))); }
/** * {@inheritdoc} */ public function url($rel = 'canonical', $options = array()) { return $this->entity->toUrl($rel, $options)->toString(); }
/** * {@inheritdoc} */ public function toUrl($rel = 'canonical', array $options = array()) { return $this->entity->toUrl($rel, $options); }