You are here

public function ConnectionAddController::addForm in RedHen CRM 8

Creation form for redhen_connection entities of given bundle/type.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request object.

\Drupal\Core\Entity\EntityInterface $redhen_connection_type: The custom bundle to add.

\Drupal\Core\Entity\EntityInterface $entity: The entity for one of the endpoints.

Return value

array A form array as expected by drupal_render().

1 call to ConnectionAddController::addForm()
ConnectionAddController::add in modules/redhen_connection/src/Controller/ConnectionAddController.php
Displays add links for available bundles/types for redhen_connection.

File

modules/redhen_connection/src/Controller/ConnectionAddController.php, line 108

Class

ConnectionAddController
Class ConnectionAddController.

Namespace

Drupal\redhen_connection\Controller

Code

public function addForm(Request $request, EntityInterface $redhen_connection_type) {
  $entity = redhen_connection_get_connection_entity_from_route();
  $endpoint_fields = $redhen_connection_type
    ->getEndpointFields($entity
    ->getEntityTypeId(), $entity
    ->getType());
  if (empty($endpoint_fields)) {

    // No valid endpoint fields found for the provided connection type and
    // entity.
    throw new NotFoundHttpException();
  }
  $connection_entity = $this->storage
    ->create([
    'type' => $redhen_connection_type
      ->id(),
  ]);

  // Grab the first field if we have more than one.
  $field = reset($endpoint_fields);

  // Set the value of the endpoint.
  $connection_entity
    ->set($field, $entity);
  return $this
    ->entityFormBuilder()
    ->getForm($connection_entity, 'default', [
    'fixed_endpoint' => $field,
  ]);
}