diff --git a/ezcontent_publish.module b/ezcontent_publish.module index 843c99e..29f90ec 100644 --- a/ezcontent_publish.module +++ b/ezcontent_publish.module @@ -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%', + ]), ]; - } } } } @@ -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'); } } @@ -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); } } diff --git a/src/Plugin/Block/EzContentUserShortcutBlock.php b/src/Plugin/Block/EzContentUserShortcutBlock.php index b84e3fa..3141ace 100644 --- a/src/Plugin/Block/EzContentUserShortcutBlock.php +++ b/src/Plugin/Block/EzContentUserShortcutBlock.php @@ -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) { @@ -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 @@ -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], @@ -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;