diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 0711c76..039bef0 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -10,8 +10,11 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\ContentEntityFormController; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Session\AccountInterface; use Drupal\Component\Utility\String; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the node edit forms. @@ -19,6 +22,13 @@ class NodeFormController extends ContentEntityFormController { /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface. + */ + protected $account; + + /** * Default settings for this content/node type. * * @var array @@ -26,6 +36,29 @@ class NodeFormController extends ContentEntityFormController { protected $settings; /** + * Constructs a NodeFormController object. + * + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + * @param \Drupal\Core\Session\AccountInterface $account + * The account for which view access should be checked. + */ + public function __construct(EntityManagerInterface $entity_manager, AccountInterface $account) { + parent::__construct($entity_manager); + $this->account = $account; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager'), + $container->get('current_user') + ); + } + + /** * {@inheritdoc} */ protected function prepareEntity() { @@ -47,7 +80,7 @@ protected function prepareEntity() { $node->$key = (int) in_array($key, $this->settings['options']); } } - $node->setAuthorId(\Drupal::currentUser()->id()); + $node->setAuthorId($this->account->id()); $node->setCreatedTime(REQUEST_TIME); } else { @@ -130,14 +163,14 @@ public function form(array $form, array &$form_state) { 'js' => array(drupal_get_path('module', 'node') . '/node.js'), ), '#weight' => 20, - '#access' => $node->isNewRevision() || \Drupal::currentUser()->hasPermission('administer nodes'), + '#access' => $node->isNewRevision() || $this->account->hasPermission('administer nodes'), ); $form['revision_information']['revision']['revision'] = array( '#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->isNewRevision(), - '#access' => \Drupal::currentUser()->hasPermission('administer nodes'), + '#access' => $this->account->hasPermission('administer nodes'), ); $form['revision_information']['revision']['log'] = array( @@ -156,7 +189,7 @@ public function form(array $form, array &$form_state) { // Node author information for administrators. $form['author'] = array( '#type' => 'details', - '#access' => \Drupal::currentUser()->hasPermission('administer nodes'), + '#access' => $this->account->hasPermission('administer nodes'), '#title' => t('Authoring information'), '#collapsed' => TRUE, '#group' => 'advanced', @@ -195,7 +228,7 @@ public function form(array $form, array &$form_state) { // Node options for administrators. $form['options'] = array( '#type' => 'details', - '#access' => \Drupal::currentUser()->hasPermission('administer nodes'), + '#access' => $this->account->hasPermission('administer nodes'), '#title' => t('Promotion options'), '#collapsed' => TRUE, '#group' => 'advanced', @@ -246,7 +279,7 @@ protected function actions(array $form, array &$form_state) { // modules to integrate with "the Save operation" of this form. Modules // need a way to plug themselves into 1) the ::submit() step, and // 2) the ::save() step, both decoupled from the pressed form button. - if ($element['submit']['#access'] && \Drupal::currentUser()->hasPermission('administer nodes')) { + if ($element['submit']['#access'] && $this->account->hasPermission('administer nodes')) { // isNew | prev status » default & publish label & unpublish label // 1 | 1 » publish & Save and publish & Save as unpublished // 1 | 0 » unpublish & Save and publish & Save as unpublished @@ -364,7 +397,7 @@ public function submit(array $form, array &$form_state) { $node->setNewRevision(); // If a new revision is created, save the current user as revision author. $node->setRevisionCreationTime(REQUEST_TIME); - $node->setRevisionAuthorId(\Drupal::currentUser()->id()); + $node->setRevisionAuthorId($this->account->id()); } $node->validated = TRUE; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php index 479927e..0f8cc64 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php @@ -21,8 +21,7 @@ class RevisionLinkDelete extends RevisionLink { public function access() { - return (\Drupal::currentUser()->hasPermission('delete revisions')) || - (\Drupal::currentUser()->hasPermission('administer nodes')); + return user_access('delete revisions') || user_access('administer nodes'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php index 7f0e4a5..13c10fd 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php @@ -21,8 +21,7 @@ class RevisionLinkRevert extends RevisionLink { public function access() { - return (\Drupal::currentUser()->hasPermission(('revert revisions')) || - (\Drupal::currentUser()->hasPermission('administer nodes')); + return user_access('revert revisions') || user_access('administer nodes'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php index 573ddfa..b5bf773 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php @@ -29,7 +29,7 @@ public function canExpose() { * See _node_access_where_sql() for a non-views query based implementation. */ public function query() { - if (!\Drupal::currentUser()->hasPermission('administer nodes')) { + if (!user_access('administer nodes')) { $table = $this->ensureMyTable(); $grants = db_or(); foreach (node_access_grants('view') as $realm => $gids) {