You are here

public function SocialGroupContentListBuilder::buildRow in Open Social 8

Same name and namespace in other branches
  1. 8.2 modules/social_features/social_group/src/Controller/SocialGroupContentListBuilder.php \Drupal\social_group\Controller\SocialGroupContentListBuilder::buildRow()
  2. 8.3 modules/social_features/social_group/src/Controller/SocialGroupContentListBuilder.php \Drupal\social_group\Controller\SocialGroupContentListBuilder::buildRow()
  3. 8.4 modules/social_features/social_group/src/Controller/SocialGroupContentListBuilder.php \Drupal\social_group\Controller\SocialGroupContentListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

modules/social_features/social_group/src/Controller/SocialGroupContentListBuilder.php, line 107

Class

SocialGroupContentListBuilder
Provides a list controller for group content from GroupContentListBuilder.

Namespace

Drupal\social_group\Controller

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\group\Entity\GroupInterface $entity */

  // Alter Group Membership table rows.
  if ($entity
    ->getContentPlugin()
    ->getPluginId() == 'group_membership') {

    // Prepare group roles.
    $roles = [];
    foreach ($entity->group_roles
      ->referencedEntities() as $group_role) {
      $roles[] = $group_role
        ->label();
    }
    if (empty($roles)) {
      $roles[] = $this
        ->t('Member');
    }
    $roles = implode(', ', $roles);

    // Get user profile.
    $profile = _social_group_get_member_profile($entity);
    if (!empty($profile)) {

      // EntityListBuilder sets the table rows using the #rows property, so we
      // need to add the render array using the 'data' key.
      $row['member']['data'] = \Drupal::entityTypeManager()
        ->getViewBuilder('profile')
        ->view($profile, 'table');
      $row['organization']['data'] = $profile
        ->get('field_profile_organization')
        ->view([
        'label' => 'hidden',
      ]);
      $row['group_role'] = $roles;
    }
  }
  else {
    $row['member'] = $entity
      ->id();
    $row['organization']['data'] = $entity
      ->toLink()
      ->toRenderable();
  }
  if (isset($row)) {
    return $row + parent::buildRow($entity);
  }
}