pino-8.x-1.2-no-core/modules/member/src/Controller/MemberController.php

modules/member/src/Controller/MemberController.php
<?php

namespace Drupal\member\Controller;

use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\member\Entity\MemberInterface;

/**
 * Class MemberController.
 *
 *  Returns responses for Member routes.
 */
class MemberController extends ControllerBase implements ContainerInjectionInterface {

  /**
   * Displays a Member  revision.
   *
   * @param int $member_revision
   *   The Member  revision ID.
   *
   * @return array
   *   An array suitable for drupal_render().
   */
  public function revisionShow($member_revision) {
    $member = $this->entityManager()->getStorage('member')->loadRevision($member_revision);
    $view_builder = $this->entityManager()->getViewBuilder('member');

    return $view_builder->view($member);
  }

  /**
   * Page title callback for a Member  revision.
   *
   * @param int $member_revision
   *   The Member  revision ID.
   *
   * @return string
   *   The page title.
   */
  public function revisionPageTitle($member_revision) {
    $member = $this->entityManager()->getStorage('member')->loadRevision($member_revision);
    return $this->t('Revision of %title from %date', ['%title' => $member->label(), '%date' => format_date($member->getRevisionCreationTime())]);
  }

  /**
   * Generates an overview table of older revisions of a Member .
   *
   * @param \Drupal\member\Entity\MemberInterface $member
   *   A Member  object.
   *
   * @return array
   *   An array as expected by drupal_render().
   */
  public function revisionOverview(MemberInterface $member) {
    $account = $this->currentUser();
    $langcode = $member->language()->getId();
    $langname = $member->language()->getName();
    $languages = $member->getTranslationLanguages();
    $has_translations = (count($languages) > 1);
    $member_storage = $this->entityManager()->getStorage('member');

    $build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $member->label()]) : $this->t('Revisions for %title', ['%title' => $member->label()]);
    $header = [$this->t('Revision'), $this->t('Operations')];

    $revert_permission = (($account->hasPermission("revert all member revisions") || $account->hasPermission('administer member entities')));
    $delete_permission = (($account->hasPermission("delete all member revisions") || $account->hasPermission('administer member entities')));

    $rows = [];

    $vids = $member_storage->revisionIds($member);

    $latest_revision = TRUE;

    foreach (array_reverse($vids) as $vid) {
      /** @var \Drupal\member\MemberInterface $revision */
      $revision = $member_storage->loadRevision($vid);
      // Only show revisions that are affected by the language that is being
      // displayed.
      if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
        $username = [
          '#theme' => 'username',
          '#account' => $revision->getRevisionUser(),
        ];

        // Use revision link to link to revisions that are not active.
        $date = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
        if ($vid != $member->getRevisionId()) {
          $link = $this->l($date, new Url('entity.member.revision', ['member' => $member->id(), 'member_revision' => $vid]));
        }
        else {
          $link = $member->link($date);
        }

        $row = [];
        $column = [
          'data' => [
            '#type' => 'inline_template',
            '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
            '#context' => [
              'date' => $link,
              'username' => \Drupal::service('renderer')->renderPlain($username),
              'message' => ['#markup' => $revision->getRevisionLogMessage(), '#allowed_tags' => Xss::getHtmlTagList()],
            ],
          ],
        ];
        $row[] = $column;

        if ($latest_revision) {
          $row[] = [
            'data' => [
              '#prefix' => '<em>',
              '#markup' => $this->t('Current revision'),
              '#suffix' => '</em>',
            ],
          ];
          foreach ($row as &$current) {
            $current['class'] = ['revision-current'];
          }
          $latest_revision = FALSE;
        }
        else {
          $links = [];
          if ($revert_permission) {
            $links['revert'] = [
              'title' => $this->t('Revert'),
              'url' => $has_translations ?
              Url::fromRoute('entity.member.translation_revert', [
                'member' => $member->id(),
                'member_revision' => $vid,
                'langcode' => $langcode,
              ]) :
              Url::fromRoute('entity.member.revision_revert', [
                'member' => $member->id(),
                'member_revision' => $vid,
              ]),
            ];
          }

          if ($delete_permission) {
            $links['delete'] = [
              'title' => $this->t('Delete'),
              'url' => Url::fromRoute('entity.member.revision_delete', ['member' => $member->id(), 'member_revision' => $vid]),
            ];
          }

          $row[] = [
            'data' => [
              '#type' => 'operations',
              '#links' => $links,
            ],
          ];
        }

        $rows[] = $row;
      }
    }

    $build['member_revisions_table'] = [
      '#theme' => 'table',
      '#rows' => $rows,
      '#header' => $header,
    ];

    return $build;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc