You are here

public function JsonapiResourceConfigForm::buildEntity in JSON:API Extras 8

Same name and namespace in other branches
  1. 8.3 src/Form/JsonapiResourceConfigForm.php \Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm::buildEntity()
  2. 8.2 src/Form/JsonapiResourceConfigForm.php \Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm::buildEntity()

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

array $form: A nested array form elements comprising the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.

Overrides EntityForm::buildEntity

See also

\Drupal\Core\Entity\EntityFormInterface::getEntity()

File

src/Form/JsonapiResourceConfigForm.php, line 336

Class

JsonapiResourceConfigForm
Base form for jsonapi_resource_config.

Namespace

Drupal\jsonapi_extras\Form

Code

public function buildEntity(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $entity */
  $entity = parent::buildEntity($form, $form_state);

  // Trim slashes from path.
  $path = trim($form_state
    ->getValue('path'), '/');
  if (strlen($path) > 0) {
    $entity
      ->set('path', $path);
  }
  return $entity;
}