shortcut_current_displayed_set example


  public function buildForm(array $form, FormStateInterface $form_state, UserInterface $user = NULL) {
    $account = $this->currentUser();

    $this->user = $user;

    // Prepare the list of shortcut sets.     $options = array_map(function DShortcutSet $set) {
      return $set->label();
    }$this->shortcutSetStorage->loadMultiple());

    $current_set = shortcut_current_displayed_set($this->user);

    // Only administrators can add shortcut sets.     $add_access = $account->hasPermission('administer shortcuts');
    if ($add_access) {
      $options['new'] = $this->t('New set');
    }

    $account_is_user = $this->user->id() == $account->id();
    if (count($options) > 1) {
      $form['set'] = [
        '#type' => 'radios',
        
$this->executeMigration('d7_menu');
    $this->executeMigration('d7_shortcut');
    $this->executeMigration('d7_shortcut_set_users');
  }

  /** * Tests the shortcut set migration. */
  public function testShortcutSetUsersMigration() {
    // Check if migrated user has correct migrated shortcut set assigned.     $account = User::load(2);
    $shortcut_set = shortcut_current_displayed_set($account);
    /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
    $this->assertSame('shortcut_set_2', $shortcut_set->id());
  }

}

class ShortcutsBlock extends BlockBase {

  /** * {@inheritdoc} */
  public function build() {
    return [
      shortcut_renderable_links(shortcut_current_displayed_set()),
    ];
  }

  /** * {@inheritdoc} */
  protected function blockAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermission($account, 'access shortcuts');
  }

}
switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access shortcuts');

      case 'update':
        if ($account->hasPermission('administer shortcuts')) {
          return AccessResult::allowed()->cachePerPermissions();
        }
        if (!$account->hasPermission('access shortcuts')) {
          return AccessResult::neutral()->cachePerPermissions();
        }
        return AccessResult::allowedIf($account->hasPermission('customize shortcut links') && $entity == shortcut_current_displayed_set($account))->cachePerPermissions()->addCacheableDependency($entity);

      case 'delete':
        return AccessResult::allowedIf($account->hasPermission('administer shortcuts') && $entity->id() != 'default')->cachePerPermissions();

      default:
        // No opinion.         return AccessResult::neutral();
    }
  }

  /** * {@inheritdoc} */
/** * Tests switching a user's own shortcut set. */
  public function testShortcutSetSwitchOwn() {
    $new_set = $this->generateShortcutSet($this->randomMachineName());

    // Attempt to switch the default shortcut set to the newly created shortcut     // set.     $this->drupalGet('user/' . $this->adminUser->id() . '/shortcuts');
    $this->submitForm(['set' => $new_set->id()], 'Change set');
    $this->assertSession()->statusCodeEquals(200);
    $current_set = shortcut_current_displayed_set($this->adminUser);
    $this->assertSame($current_set->id()$new_set->id(), 'Successfully switched own shortcut set.');
  }

  /** * Tests switching another user's shortcut set. */
  public function testShortcutSetAssign() {
    $new_set = $this->generateShortcutSet($this->randomMachineName());

    \Drupal::entityTypeManager()->getStorage('shortcut_set')->assignUser($new_set$this->shortcutUser);
    $current_set = shortcut_current_displayed_set($this->shortcutUser);
    
public static function trustedCallbacks() {
    return ['lazyLinks'];
  }

  /** * #lazy_builder callback; builds shortcut toolbar links. * * @return array * A renderable array of shortcut links. */
  public function lazyLinks() {
    $shortcut_set = shortcut_current_displayed_set();

    $links = shortcut_renderable_links();

    $configure_link = NULL;
    if (shortcut_set_edit_access($shortcut_set)->isAllowed()) {
      $configure_link = [
        '#type' => 'link',
        '#title' => t('Edit shortcuts'),
        '#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['shortcut_set' => $shortcut_set->id()]),
        '#options' => ['attributes' => ['class' => ['edit-shortcuts']]],
      ];
    }
new EntityCondition('uri', 'public://', 'STARTS_WITH'),
          new EntityCondition('uid', $current_user->id()),
        ]);
        $cacheability->addCacheTags($entity_type->getListCacheTags());
        break;

      case 'shortcut':
        // Unless the user can administer shortcuts, allow access only to the         // user's currently displayed shortcut set.         // @see \Drupal\shortcut\ShortcutAccessControlHandler::checkAccess()         if (!$current_user->hasPermission('administer shortcuts')) {
          $specific_condition = new EntityCondition('shortcut_set', shortcut_current_displayed_set()->id());
          $cacheability->addCacheContexts(['user']);
          $cacheability->addCacheTags($entity_type->getListCacheTags());
        }
        break;

      case 'user':
        // Disallow querying values of the anonymous user.         // @see \Drupal\user\UserAccessControlHandler::checkAccess()         $specific_condition = new EntityCondition('uid', '0', '!=');
        break;
    }

    
Home | Imprint | This part of the site doesn't use cookies.