You are here

public function EntityconnectController::edit in Entity connect 8.2

Page callback: Redirect to edit form.

Parameters

string $cache_id: The id of the parent form cache.

Return value

array|RedirectResponse The page of the entity to edit or list of entities.

1 string reference to 'EntityconnectController::edit'
entityconnect.routing.yml in ./entityconnect.routing.yml
entityconnect.routing.yml

File

src/Controller/EntityconnectController.php, line 116

Class

EntityconnectController
Returns responses for Entityconnect module routes.

Namespace

Drupal\entityconnect\Controller

Code

public function edit($cache_id) {
  $data = $this->entityconnectCache
    ->get($cache_id);
  $entity_type = $data['target_entity_type'];
  $target_id = $this
    ->fixTargetId($data['target_id']);
  $args = [
    $cache_id,
    $entity_type,
    $target_id,
  ];
  $edit_info = $this
    ->moduleHandler()
    ->invokeAll('entityconnect_edit_info', $args);

  // Merge in default values.
  foreach ($edit_info as $data) {
    $edit_info += [
      'content' => [
        'href' => '',
        'label' => '',
        'description' => '',
      ],
      'theme_callback' => 'entityconnect_entity_add_list',
    ];
  }
  $context = [
    'cache_id' => $cache_id,
    'entity_type' => $entity_type,
    'target_id' => $target_id,
  ];
  $this
    ->moduleHandler()
    ->alter('entityconnect_edit_info', $edit_info, $context);
  if (isset($edit_info)) {
    $content = $edit_info['content'];
    $theme = $edit_info['theme_callback'];
    if (count($content) == 1) {
      $item = array_pop($content);
      if (is_array($item['href'])) {
        $url = array_shift($item['href']);
      }
      else {
        $url = $item['href'];
      }
      if (!$url) {
        $this
          ->returnWithMessage($this
          ->t('Invalid url: %url', [
          '%url' => $url,
        ]), 'warning', $cache_id);
      }
      return new RedirectResponse($url);
    }
    return [
      '#theme' => $theme,
      '#items' => $content,
      '#cache_id' => $cache_id,
      '#cancel_link' => Link::createFromRoute($this
        ->t('Cancel'), 'entityconnect.return', [
        'cache_id' => $cache_id,
        'cancel' => TRUE,
      ]),
    ];
  }
  return $this
    ->returnWithMessage($this
    ->t('Nothing to edit.'), 'warning', $cache_id);
}