You are here

public static function SocialAlbumEntityOperations::renderLinks in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_album/src/Plugin/views/field/SocialAlbumEntityOperations.php \Drupal\social_album\Plugin\views\field\SocialAlbumEntityOperations::renderLinks()
  2. 10.0.x modules/social_features/social_album/src/Plugin/views/field/SocialAlbumEntityOperations.php \Drupal\social_album\Plugin\views\field\SocialAlbumEntityOperations::renderLinks()
  3. 10.2.x modules/social_features/social_album/src/Plugin/views/field/SocialAlbumEntityOperations.php \Drupal\social_album\Plugin\views\field\SocialAlbumEntityOperations::renderLinks()

Lazy_builder callback; builds a post's links.

Parameters

int $node_id: The post entity ID.

int $post_id: The post entity ID.

int $file_id: The file entity ID.

Return value

array A renderable array representing the post links.

File

modules/social_features/social_album/src/Plugin/views/field/SocialAlbumEntityOperations.php, line 56

Class

SocialAlbumEntityOperations
Renders all operations links for a post.

Namespace

Drupal\social_album\Plugin\views\field

Code

public static function renderLinks($node_id, $post_id, $file_id) {
  $entity = \Drupal::entityTypeManager()
    ->getStorage('post')
    ->load($post_id);
  $links = call_user_func([
    \Drupal::entityTypeManager()
      ->getViewBuilder('post'),
    __FUNCTION__,
  ], $post_id, 'default', $entity
    ->language()
    ->getId(), !empty($entity->in_preview));
  if (isset($links['post']['#links']['delete'])) {
    $url = Url::fromRoute('social_album.image.delete', [
      'node' => $node_id,
      'post' => $post_id,
      'fid' => $file_id,
    ]);
    if ($url
      ->access()) {
      $links['post']['#links']['delete']['url'] = $url;
    }
    else {
      unset($links['post']['#links']['delete']);
    }
  }
  return $links;
}