Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZ-770: Enhancement, adding shortcut and list shortcut in a modal-box #64

Merged
merged 1 commit into from Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions ezcontent_publish.module
Expand Up @@ -84,16 +84,23 @@ function ezcontent_publish_form_shortcut_set_customize_form_alter(&$form, $form_
foreach ($form['shortcuts']['links'] as $key => $value) {
if (is_numeric($key)) {
$form['shortcuts']['links'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('ezcontent_publish.shortcut.edit_form', array('shortcut' => $key));
$form['shortcuts']['links'][$key]['operations']['#links']['edit']['attributes'] = [
'class' => ['use-ajax'],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-dialog-options' => json_encode([
'width' => '50%',
]),
];
$form['shortcuts']['links'][$key]['operations']['#links']['delete']['url'] = Url::fromRoute('ezcontent_publish.shortcut.delete_form', array('shortcut' => $key));
$currentUserRoles = $currentUser->getRoles();
if (!in_array('administrator', $currentUserRoles)) {
$currentUrl = ltrim(\Drupal::service('path.current')->getPath(), '/');
$addShortcutUrl = Url::fromRoute('ezcontent_publish.shortcut.link_add', array('shortcut_set' => 'shortcut_set_' . $currentUser->getUsername() . '_' . $currentUser->id()), ['query' => ['destination' => $currentUrl]]);
$addShortcutLink = Link::fromTextAndUrl(t('Add Shortcut'), $addShortcutUrl)->toString();
$form['add_shortcut_link'] = [
'#markup' => $addShortcutLink
$form['shortcuts']['links'][$key]['operations']['#links']['delete']['attributes'] = [
'class' => ['use-ajax'],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-dialog-options' => json_encode([
'width' => '30%',
]),
];
}
}
}
}
Expand All @@ -115,6 +122,7 @@ function ezcontent_publish_form_alter(&$form, $form_state, $form_id) {
];
if (in_array($form_id, $formIds)) {
$form['actions']['submit']['#submit'][] = 'ezcontent_publish_shortcut_form_submit';
$form['actions']['cancel']['#url'] = Url::fromRoute('user.page');
}
}

Expand All @@ -123,8 +131,7 @@ function ezcontent_publish_form_alter(&$form, $form_state, $form_id) {
*/
function ezcontent_publish_shortcut_form_submit(array $form, $form_state) {
if (!in_array('administrator', \Drupal::currentUser()->getRoles())) {
$shortcutSet = $form_state->getFormObject()->getEntity()->get('shortcut_set')->getValue()[0]['target_id'];
$redirectUrl = Url::fromRoute('ezcontent_publish.shortcut_set.customize_form', array('shortcut_set' => $shortcutSet));
$redirectUrl = Url::fromRoute('user.page');
$form_state->setRedirectUrl($redirectUrl);
}
}
29 changes: 26 additions & 3 deletions src/Plugin/Block/EzContentUserShortcutBlock.php
Expand Up @@ -38,7 +38,7 @@ class EzContentUserShortcutBlock extends BlockBase implements ContainerFactoryPl
* @param mixed $plugin_definition
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) {
Expand Down Expand Up @@ -70,9 +70,10 @@ public static function create(ContainerInterface $container, array $configuratio
*/
public function build() {
$build = [];
// Getting current user role.
$currentUserRoles = $this->account->getRoles();
if ($this->account->hasPermission('ezcontent shortcut set creation') && $this->account->id() != '1') {
// Getting current user role.
if (!in_array('administrator', $this->account->getRoles())) {
if (!in_array('administrator', $currentUserRoles)) {
$currentUserId = $this->account->id();
$currentUsername = $this->account->getUsername();
$currentShortcutset = $this->entityTypeManager
Expand All @@ -99,6 +100,11 @@ public function build() {

$build = [
'#theme' => 'user_shortcut_block_template',
'#attached' => [
'library' => [
'core/drupal.dialog.ajax',
],
],
'#data' => $shortcutObj,
'#cache' => [
'tags' => ['config:shortcut.set.' . $shortcutSetId],
Expand Down Expand Up @@ -129,7 +135,24 @@ public function getUserShortcutLinks($currentUserShortcutSet) {
$shortcutLink = $currentUserShortcutObj->get('link')->first()->getUrl();
$shortcutObj['links'][] = Link::fromTextAndUrl($shortcutTitle, $shortcutLink)->toRenderable();
}
$addShortcutLink['#attributes'] = [
'class' => ['use-ajax'],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-dialog-options' => json_encode([
'width' => '50%',
]),
];
$shortcutObj['operations']['add_link'] = $addShortcutLink;

$operationShortcutLink['#attributes'] = [
'class' => ['use-ajax'],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-dialog-options' => json_encode([
'width' => '40%',
]),
];
$shortcutObj['operations']['manage_link'] = $operationShortcutLink;

return $shortcutObj;
Expand Down