You are here

class AbrconfigListBuilder in Access by Reference 8.2

Provides a listing of Example.

Hierarchy

Expanded class hierarchy of AbrconfigListBuilder

File

src/Controller/AbrconfigListBuilder.php, line 12

Namespace

Drupal\access_by_ref\Controller
View source
class AbrconfigListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this
      ->t('Machine name');
    $header['label'] = $this
      ->t('Label');
    $header['bundle'] = $this
      ->t('Bundle');
    $header['field'] = $this
      ->t('Field');
    $header['reference_type'] = $this
      ->t('Reference type');
    $header['extra'] = $this
      ->t('Extra');
    $header['rights_type'] = $this
      ->t('Rights type');
    $header['rights_read'] = $this
      ->t('Read?');
    $header['rights_update'] = $this
      ->t('Update?');
    $header['rights_delete'] = $this
      ->t('Delete?');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['id'] = $entity
      ->id();
    $row['label'] = $entity
      ->label();
    $row['bundle'] = $entity
      ->getBundle();
    $row['field'] = $entity
      ->getField();
    $row['reference_type'] = $entity
      ->getReferencetype(true);
    $row['extra'] = $entity
      ->getExtra();
    $row['rights_type'] = $entity
      ->getRightsType();
    $row['rights_read'] = $entity
      ->getRightsRead() == true ? 'X' : '';
    $row['rights_update'] = $entity
      ->getRightsUpdate() == true ? 'X' : '';
    $row['rights_delete'] = $entity
      ->getRightsDelete() == true ? 'X' : '';

    // You probably want a few more properties here...
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbrconfigListBuilder::buildHeader public function Builds the header row for the entity listing. Overrides EntityListBuilder::buildHeader
AbrconfigListBuilder::buildRow public function Builds a row for an entity in the entity listing. Overrides EntityListBuilder::buildRow
AbrconfigListBuilder::render public function Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder::render
ConfigEntityListBuilder::getDefaultOperations public function Gets this list's default operations. Overrides EntityListBuilder::getDefaultOperations 15
ConfigEntityListBuilder::load public function Loads entities of this type from storage for listing. Overrides EntityListBuilder::load 7
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityHandlerBase::$moduleHandler protected property The module handler to invoke hooks on. 2
EntityHandlerBase::moduleHandler protected function Gets the module handler. 2
EntityHandlerBase::setModuleHandler public function Sets the module handler for this handler.
EntityListBuilder::$entityType protected property Information about the entity type.
EntityListBuilder::$entityTypeId protected property The entity type ID.
EntityListBuilder::$limit protected property The number of entities to list per page, or FALSE to list all entities. 3
EntityListBuilder::$storage protected property The entity storage class. 1
EntityListBuilder::buildOperations public function Builds a renderable list of operation links for the entity. 2
EntityListBuilder::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance 20
EntityListBuilder::ensureDestination protected function Ensures that a destination is present on the given URL.
EntityListBuilder::getEntityIds protected function Loads entity IDs using a pager sorted by the entity id. 4
EntityListBuilder::getLabel Deprecated protected function Gets the label of an entity.
EntityListBuilder::getOperations public function Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface::getOperations 2
EntityListBuilder::getStorage public function Gets the entity storage. Overrides EntityListBuilderInterface::getStorage
EntityListBuilder::getTitle protected function Gets the title of the page. 1
EntityListBuilder::__construct public function Constructs a new EntityListBuilder object. 16
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.