You are here

public function AbrconfigListBuilder::render in Access by Reference 8.2

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

src/Controller/AbrconfigListBuilder.php, line 55

Class

AbrconfigListBuilder
Provides a listing of Example.

Namespace

Drupal\access_by_ref\Controller

Code

public function render() {
  $info = "<p>Lightweight module that extends read, update or delete permissions to a user in the following cases: </p> ";
  $info .= "<ol>";
  $info .= "<li><strong>User: </strong>The node <em>references the user</em></li>";
  $info .= "<li><strong>User's mail: </strong>The node <em>references the user's e-mail</em></li> ";
  $info .= "<li><strong>Profile value: </strong>The node has a value in a specified field that <em>is the same as one in the user's profile</em></li>";
  $info .= "<li><strong>Inherit from parent: </strong> The node <em>references a node</em> that the user has certain permissions on. </li>";
  $info .= "</ol>";
  $info .= "<p>In each case, the rule only applies to logged-in users with general permission to access nodes by reference, and only on the node types and field names set in the configuration page. </p>";
  $info .= "<p>Permissions are <strong>chainable</strong>, but note that there is no protection against infinite loops, so some care is advised in configuration.";

  // <li><b>Link FROM Parent:</b> <i>Risky</i> The node is referenced from a node the user can edit. If the user can edit that field, it gives them extensive control over site content</li>
  // <li><b>Secret Code:</b> <i>Experimental</i> The URL includes a parameter that matches the value of the field. E.g. ?field_foo=bar</li>
  $info .= "<p>These accesses will only be available to a user with the Access By Reference permissions, so be sure to set those</p>";
  $info .= "<p><b>To Use:</b> Select the content type to be controlled, and then the type of access you want to grant. Choose the field that will contain the effective data or link. In case we are looking for matched values, such as the 'Profile Value', specify in the Extra Field the field in the User Profile that has to match</p>";
  $form['info'] = array(
    '#type' => 'item',
    '#markup' => $info,
  );
  $build['description'] = [
    '#prefix' => '<div>',
    '#markup' => $this
      ->t($info, [
      ':components' => Url::fromRoute('entity.abrconfig.collection')
        ->toString(),
      ':documentation' => 'https://www.drupal.org/node/',
    ]),
    '#suffix' => '</div>',
  ];
  $build['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#title' => $this
      ->getTitle(),
    '#rows' => [],
    '#empty' => $this
      ->t('There are no @label yet.', [
      '@label' => $this->entityType
        ->getPluralLabel(),
    ]),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];
  foreach ($this
    ->load() as $entity) {
    if ($row = $this
      ->buildRow($entity)) {
      $build['table']['#rows'][$entity
        ->id()] = $row;
    }
  }

  // Only add the pager if a limit is specified.
  if ($this->limit) {
    $build['pager'] = [
      '#type' => 'pager',
    ];
  }
  return $build;
}