Commit 26fe9060 authored by xem8vfdh's avatar xem8vfdh Committed by Gisle Hannemyr
Browse files

Issue #3042944 by xeM8VfDh, Sergiu Stici, gisle: Drupal 9 Deprecated Code Report

parent 60d6ac86
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,3 +7,6 @@ package: 'Access control'

dependencies:
  - drupal:node

test_dependencies:
  - drupal:acl
+1 −1
Original line number Diff line number Diff line
@@ -772,7 +772,7 @@ function content_access_user_admin_perm_submit($form, FormStateInterface $form_s
    }
  }
  if ($types && content_access_mass_update(array_keys($types))) {
    drupal_set_message(\Drupal::translation()->formatPlural(count($types),
    \Drupal::messenger()->addMessage(\Drupal::translation()->formatPlural(count($types),
      'Permissions have been successfully rebuilt for the content type @types.',
      'Permissions have been successfully rebuilt for the content types @types.',
      ['@types' => implode(', ', $types)]
+3 −3
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class ContentAccessAdminSettingsForm extends FormBase {
      '#title' => t('Per content node access control settings'),
      '#collapsible' => TRUE,
      '#description' => t('Optionally you can enable per content node access control settings. If enabled, a new tab for the content access settings appears when viewing content. You have to configure permission to access these settings at the @permissions page.', [
        '@permissions' => \Drupal::l(t('permissions'), Url::fromRoute('user.admin_permissions')),
        '@permissions' => Link::fromTextAndUrl(t('permissions'), Url::fromRoute('user.admin_permissions')),
      ]),
    ];
    $form['node']['per_node'] = [
@@ -165,11 +165,11 @@ class ContentAccessAdminSettingsForm extends FormBase {

      if (content_access_mass_update([$node_type])) {
        $node_types = node_type_get_names();
        drupal_set_message(t('Permissions have been successfully rebuilt for the content type @types.', ['@types' => $node_types[$node_type]]));
        $this->messenger()->addMessage(t('Permissions have been successfully rebuilt for the content type @types.', ['@types' => $node_types[$node_type]]));
      }
    }

    drupal_set_message(t('Your changes have been saved.'));
    $this->messenger()->addMessage(t('Your changes have been saved.'));
  }

  /**
+7 −7
Original line number Diff line number Diff line
@@ -12,9 +12,9 @@ use Drupal\Core\Session\AccountInterface;

/**
 * Node Access settings form.
 * @package Drupal\content_access\Form
 */
class ContentAccessPageForm extends FormBase {

  use ContentAccessRoleBasedFormTrait;

  /**
@@ -99,7 +99,7 @@ class ContentAccessPageForm extends FormBase {
    // @todo not true anymore?
    // http://drupal.org/update/modules/6/7#hook_node_access_records
    if (!$node->isPublished()) {
      drupal_set_message(t("Warning: Your content is not published, so this settings are not taken into account as long as the content remains unpublished."), 'error');
      $this->messenger()->addError(t("Warning: Your content is not published, so this settings are not taken into account as long as the content remains unpublished."));
    }

    return $form;
@@ -124,7 +124,7 @@ class ContentAccessPageForm extends FormBase {
    content_access_save_per_node_settings($node, $settings);

    if (\Drupal::moduleHandler()->moduleExists('acl')) {
      foreach (['view', 'update', 'delete'] as $op) {
      foreach (array('view', 'update', 'delete') as $op) {
        $values = $form_state->getValues();
        acl_save_form($values['acl'][$op]);
        \Drupal::moduleHandler()->invokeAll('user_acl', $settings);
@@ -132,14 +132,14 @@ class ContentAccessPageForm extends FormBase {
    }

    // Apply new settings.
    \Drupal::entityTypeManager()->getAccessControlHandler('node')->writeGrants($node);
    \Drupal::entityManager()->getAccessControlHandler('node')->writeGrants($node);
    \Drupal::moduleHandler()->invokeAll('per_node', $settings);

    foreach (Cache::getBins() as $service_id => $cache_backend) {
      $cache_backend->deleteAll();
    }

    drupal_set_message(t('Your changes have been saved.'));
    $this->messenger()->addMessage(t('Your changes have been saved.'));
  }

  /**
@@ -181,9 +181,9 @@ class ContentAccessPageForm extends FormBase {
  function pageResetSubmit(array &$form, FormStateInterface $form_state) {
    $storage = $form_state->getStorage();
    content_access_delete_per_node_settings($storage['node']);
    \Drupal::entityTypeManager()->getAccessControlHandler('node')->writeGrants($storage['node']);
    \Drupal::entityManager()->getAccessControlHandler('node')->writeGrants($storage['node']);

    drupal_set_message(t('The permissions have been reset to the content type defaults.'));
    $this->messenger()->addMessage(t('The permissions have been reseted to the content type defaults.'));
  }


+44 −9
Original line number Diff line number Diff line
@@ -2,23 +2,28 @@

namespace Drupal\content_access\Tests;

use Drupal\Core\Session\AccountInterface;
use Drupal\simpletest\WebTestBase;

/**
 * Automated SimpleTest Case for using content access module with acl module.
 *
 * @group Access
 */
class ContentAccessAclTestCase extends ContentAccessTestHelp {
class ContentAccessAclTestCase extends WebTestBase {
  use ContentAccessTestHelperTrait;

  /**
   * Implementation of getInfo() for information.
   * Modules to enable.
   *
   * @var array
   */
  public static function getInfo() {
    return [
      'name' => t('Content Access Module with ACL Module Tests'),
      'description' => t('Various tests to check the combination of content access and ACL module.'),
      'group' => 'Content Access',
    ];
  }
  public static $modules = ['content_access', 'acl'];

  protected $test_user;
  protected $admin_user;
  protected $content_type;
  protected $node1;

  /**
   * Setup configuration before each test.
@@ -31,6 +36,36 @@ class ContentAccessAclTestCase extends ContentAccessTestHelp {
      return;
    }

    // Create test user with separate role.
    $this->test_user = $this->drupalCreateUser();

    // Get the value of the new role.
    // @see drupalCreateUser().
    $test_user_roles = $this->test_user->getRoles();
    foreach ($test_user_roles as $role) {
      if (!in_array($role, [AccountInterface::AUTHENTICATED_ROLE])) {
        $this->rid = $role;
        break;
      }
    }

    // Create admin user.
    $this->admin_user = $this->drupalCreateUser([
      'access content',
      'administer content types',
      'grant content access',
      'grant own content access',
      'administer nodes',
      'access administration pages'
    ]);
    $this->drupalLogin($this->admin_user);

    // Rebuild content access permissions.
    node_access_rebuild();

    // Create test content type.
    $this->content_type = $this->drupalCreateContentType();

    // Create test node.
    $this->node1 = $this->drupalCreateNode(['type' => $this->content_type->id()]);
  }
Loading