You are here

public static function EntityconnectController::editInfo in Entity connect 8.2

Callback for creating the build array of entities to edit.

Parameters

string $cache_id: The id of parent form cache.

string $entity_type: The target entity type.

array|int $target_id: The target id.

Return value

array The edit build array.

Throws

\Exception

1 call to EntityconnectController::editInfo()
entityconnect_entityconnect_edit_info in ./entityconnect.module
Implements hook_entityconnect_edit_info().

File

src/Controller/EntityconnectController.php, line 192

Class

EntityconnectController
Returns responses for Entityconnect module routes.

Namespace

Drupal\entityconnect\Controller

Code

public static function editInfo($cache_id, $entity_type, $target_id) {
  if (empty($entity_type)) {
    throw new \Exception('Entity type can not be empty');
  }
  if (empty($target_id)) {
    throw new \Exception('Target_id can not be empty');
  }
  $content = [];
  $options = [
    'query' => [
      'build_cache_id' => $cache_id,
      'child' => TRUE,
    ],
    'absolute' => TRUE,
  ];
  if (is_array($target_id)) {
    $info = \Drupal::entityTypeManager()
      ->getStorage($entity_type)
      ->loadMultiple($target_id);
    foreach ($info as $key => $value) {
      $content[$key] = [
        'label' => $value
          ->label(),
        'href' => \Drupal::urlGenerator()
          ->generateFromRoute('entity.' . $entity_type . '.edit_form', [
          $entity_type => $key,
        ], $options),
        'description' => '',
      ];
    }
  }
  else {
    $content[$entity_type]['href'] = \Drupal::urlGenerator()
      ->generateFromRoute('entity.' . $entity_type . '.edit_form', [
      $entity_type => $target_id,
    ], $options);
  }
  return [
    'content' => $content,
  ];
}