Loading ajax_comments.module +16 −19 Original line number Diff line number Diff line Loading @@ -6,28 +6,20 @@ */ use Drupal\ajax_comments\Controller\AjaxCommentsController; use Drupal\ajax_comments\FieldSettingsHelper; use Drupal\ajax_comments\Utility; use Drupal\comment\CommentInterface; use Drupal\node\NodeInterface; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Html; use Drupal\Core\Ajax; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\AlertCommand; use Drupal\Core\Ajax\CloseDialogCommand; use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatch; use Symfony\Component\HttpFoundation\Request; /** * Implements hook_comment_links_alter(). Loading @@ -35,8 +27,7 @@ use Symfony\Component\HttpFoundation\Request; * For entity bundles with ajax comments enabled, alter the comment link * classes to allow ajax behaviors to be attached. */ function ajax_comments_comment_links_alter(array &$links, CommentInterface &$entity, array &$context) { $request = \Drupal::request(); function ajax_comments_comment_links_alter(array &$links, CommentInterface $entity, array &$context) { /** @var \Drupal\ajax_comments\FieldSettingsHelper $field_settings_helper */ $field_settings_helper = \Drupal::service('ajax_comments.field_settings_helper'); $comment_formatter = $field_settings_helper->getFieldFormatterFromComment($entity, $context['view_mode']); Loading Loading @@ -135,7 +126,11 @@ function ajax_comments_node_links_alter(array &$node_links, NodeInterface $node, $links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); foreach ($links as $link_name => $link) { $field_name = substr($link_name, strlen('comment__')); $classes = ['js-use-ajax-comments', 'js-ajax-comments-reply', 'js-ajax-comments-reply-' . $node->id() . '-' . $field_name . '-0']; $classes = [ 'js-use-ajax-comments', 'js-ajax-comments-reply', 'js-ajax-comments-reply-' . $node->id() . '-' . $field_name . '-0', ]; if (!empty($link['#links']['comment-add'])) { if (empty($link['#links']['comment-add']['attributes']['class'])) { $links[$link_name]['#links']['comment-add']['attributes']['class'] = $classes; Loading Loading @@ -218,7 +213,10 @@ function ajax_comments_form_comment_form_alter(&$form, FormStateInterface $form_ // If the user is on the standalone comment reply page, it means JavaScript // is disabled or the ajax functionality is not working. Do not proceed with // the form alter. if (in_array($current_route->getRouteName(), ['comment.reply', 'entity.comment.edit_form'])) { if (in_array($current_route->getRouteName(), [ 'comment.reply', 'entity.comment.edit_form', ])) { return; } Loading @@ -226,7 +224,6 @@ function ajax_comments_form_comment_form_alter(&$form, FormStateInterface $form_ $comment = $form_state->getFormObject()->getEntity(); /** @var \Drupal\Core\Entity\EntityInterface $commented_entity */ $commented_entity = $comment->getCommentedEntity(); $field_name = $comment->getFieldName(); // Check to see if this node type uses ajax comments. $comment_formatter = $field_settings_helper->getFieldFormatterFromComment($comment, 'full'); Loading Loading @@ -299,11 +296,11 @@ function ajax_comments_preprocess_pager(&$variables) { // Query parameters are added in // core/includes/pager.inc in the template_preprocess_pager(), // where pager_query_add_page() calls pager_get_query_parameters(), // which will pick up the ajax wrapper format from the ajax request, which breaks // the pager. // Unfortunately there is no way to remove this parameter before it is rendered to text, // so this preprocess function removes the parameter with string replacement. // which will pick up the ajax wrapper format from the ajax request, // which breaks the pager. // Unfortunately there is no way to remove this parameter before it is // rendered to text, so this preprocess function removes the parameter with // string replacement. // Remove ajax wrapper format from first, previous. if (isset($variables['items']['first'])) { $variables['items']['first']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['first']['href']); Loading src/Ajax/ajaxCommentsScrollToElementCommand.php→src/Ajax/AjaxCommentsScrollToElementCommand.php +2 −7 Original line number Diff line number Diff line <?php /** * @file * Contains \Drupal\ajax_comments\Ajax\ajaxCommentsScrollToElementCommand. */ namespace Drupal\ajax_comments\Ajax; use Drupal\Core\Ajax\CommandInterface; Loading @@ -14,7 +9,7 @@ use Drupal\Core\Ajax\CommandInterface; * * @ingroup ajax */ class ajaxCommentsScrollToElementCommand Implements CommandInterface { class AjaxCommentsScrollToElementCommand implements CommandInterface { /** * The CSS selector for the element. Loading @@ -27,7 +22,7 @@ class ajaxCommentsScrollToElementCommand Implements CommandInterface { * Constructs a ajaxCommentsScrollToElementCommand object. * * @param string $selector * * The selector for the command. */ public function __construct($selector) { $this->selector = $selector; Loading src/Controller/AjaxCommentsController.php +49 −20 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ use Drupal\Core\Ajax\InvokeCommand; use Drupal\Core\Ajax\PrependCommand; use Drupal\Core\Ajax\RemoveCommand; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; Loading Loading @@ -72,6 +73,20 @@ class AjaxCommentsController extends ControllerBase { */ protected $messenger; /** * The Configuration Factory service. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** * The current user account. * * @var \Drupal\Core\Session\AccountInterface */ protected $currentUser; /** * Constructs a AjaxCommentsController object. * Loading @@ -87,14 +102,17 @@ class AjaxCommentsController extends ControllerBase { * The TempStore service. * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The Messenger service. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The Configuration Factory service. */ public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, RendererInterface $renderer, RouterInterface $router, TempStore $temp_store, MessengerInterface $messenger) { public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, RendererInterface $renderer, RouterInterface $router, TempStore $temp_store, MessengerInterface $messenger, ConfigFactoryInterface $config_factory) { $this->entityTypeManager = $entity_type_manager; $this->currentUser = $current_user; $this->renderer = $renderer; $this->router = $router; $this->tempStore = $temp_store; $this->messenger = $messenger; $this->configFactory = $config_factory; } /** Loading @@ -107,7 +125,8 @@ class AjaxCommentsController extends ControllerBase { $container->get('renderer'), $container->get('router.no_access_checks'), $container->get('ajax_comments.temp_store'), $container->get('messenger') $container->get('messenger'), $container->get('config.factory') ); } Loading Loading @@ -228,7 +247,7 @@ class AjaxCommentsController extends ControllerBase { * The modified ajax response. */ protected function addMessages(Request $request, AjaxResponse $response, $selector = '', $position = 'prepend') { $settings = \Drupal::config('ajax_comments.settings'); $settings = $this->configFactory->get('ajax_comments.settings'); $notify = $settings->get('notify'); if ($notify || !empty($this->messenger->messagesByType(MessengerInterface::TYPE_ERROR))) { Loading Loading @@ -332,15 +351,17 @@ class AjaxCommentsController extends ControllerBase { $form = $this->entityFormBuilder()->getForm($comment); $response->addCommand(new AfterCommand(static::getCommentSelectorPrefix() . $comment->id(), $form)); // TODO: Get this custom ajax command working later. // @todo Get this custom ajax command working later. // @codingStandardsIgnoreStart // if (\Drupal::config('ajax_comments.settings')->get('enable_scroll')) { // $response->addCommand(new ajaxCommentsScrollToElementCommand('.ajax-comments-reply-form-' . $comment->getCommentedEntityId() . '-' . $comment->get('pid')->target_id . '-' . $comment->id())); // } // @codingStandardsIgnoreEnd // Don't delete the tempStore variables here; we need them // to persist for the save() method below, where the form returned // here will be submitted. // Instead, return the response without calling $this->tempStore->deleteAll(). // Instead, return the response without calling // $this->tempStore->deleteAll(). return $response; } else { Loading Loading @@ -416,7 +437,7 @@ class AjaxCommentsController extends ControllerBase { $cid = $this->tempStore->getCid(); // Try to insert the message above the new comment. if (!empty($cid) && !$errors && \Drupal::currentUser()->hasPermission('skip comment approval')) { if (!empty($cid) && !$errors && $this->currentUser()->hasPermission('skip comment approval')) { $selector = static::getCommentSelectorPrefix() . $cid; $response = $this->addMessages( $request, Loading Loading @@ -454,10 +475,10 @@ class AjaxCommentsController extends ControllerBase { // core/misc/drupal.js is reinserted into the DOM, the following line of // code will execute, causing Drupal.attachBehaviors() to run on the entire // document, and reattach behaviors to DOM elements that already have them: // @code // @codingStandardsIgnoreStart // // Attach all behaviors. // domready(function () { Drupal.attachBehaviors(document, drupalSettings); }); // @endcode // @codingStandardsIgnoreEnd $attachments = $response->getAttachments(); // Need to have only 'core/drupalSettings' in the asset library list. // If neither 'core/drupalSettings', nor a library with a dependency on it, Loading Loading @@ -494,10 +515,17 @@ class AjaxCommentsController extends ControllerBase { if ($cid != 0) { // Show the hidden anchor. $response->addCommand(new InvokeCommand('a#comment-' . $cid, 'show', [200, 'linear'])); $response->addCommand(new InvokeCommand( 'a#comment-' . $cid, 'show', [200, 'linear'] ) ); // Show the hidden comment. $response->addCommand(new InvokeCommand(static::getCommentSelectorPrefix() . $cid, 'show', [200, 'linear'])); $response->addCommand(new InvokeCommand( static::getCommentSelectorPrefix() . $cid, 'show', [200, 'linear'] ) ); } // Remove the form. Loading Loading @@ -658,10 +686,10 @@ class AjaxCommentsController extends ControllerBase { // core/misc/drupal.js is reinserted into the DOM, the following line of // code will execute, causing Drupal.attachBehaviors() to run on the entire // document, and reattach behaviors to DOM elements that already have them: // @code // @codingStandardsIgnoreStart // // Attach all behaviors. // domready(function () { Drupal.attachBehaviors(document, drupalSettings); }); // @endcode // @codingStandardsIgnoreEnd $attachments = $response->getAttachments(); // Need to have only 'core/drupalSettings' in the asset library list. // If neither 'core/drupalSettings', nor a library with a dependency on it, Loading Loading @@ -738,7 +766,8 @@ class AjaxCommentsController extends ControllerBase { // Don't delete the tempStore variables here; we need them // to persist for the saveReply() method, where the form returned // here will be submitted. // Instead, return the response without calling $this->tempStore->deleteAll(). // Instead, return the response without calling // $this->tempStore->deleteAll(). return $response; } else { Loading Loading @@ -794,21 +823,21 @@ class AjaxCommentsController extends ControllerBase { // Build a dummy comment entity to pass to $this->save(), which will use // it to rebuild the comment entity form to trigger form submission. // @code // @codingStandardsIgnoreStart // $form = $this->entityFormBuilder()->getForm($comment, 'default', ['editing' => TRUE]); // @endcode // @codingStandardsIgnoreEnd // Note that this approach will correctly process the form submission // even though we are passing in an empty, dummy comment, because two steps // later in the call stack, \Drupal\Core\Form\FormBuilder::buildForm() is // called, and it checks the current request object for form submission // values if there aren't any in the form state, yet: // @code // @codingStandardsIgnoreStart // $input = $form_state->getUserInput(); // if (!isset($input)) { // $input = $form_state->isMethodType('get') ? $request->query->all() : $request->request->all(); // $form_state->setUserInput($input); // } // @endcode // @codingStandardsIgnoreEnd // This approach is very similar to the one taken in // \Drupal\comment\CommentLazyBuilders::renderForm(). $comment = $this->entityTypeManager()->getStorage('comment')->create([ Loading Loading @@ -836,7 +865,7 @@ class AjaxCommentsController extends ControllerBase { * (optional) Some comments are replies to other comments. In those cases, * $pid is the parent comment's comment ID. Defaults to NULL. * * @return \Drupal\Core\Ajax\AjaxResponse $response * @return \Drupal\Core\Ajax\AjaxResponse * The ajax response, if access is denied. */ public function replyAccess(Request $request, AjaxResponse $response, EntityInterface $entity, $field_name, $pid = NULL) { Loading @@ -855,7 +884,7 @@ class AjaxCommentsController extends ControllerBase { if (empty($selector)) { $selector = $wrapper_html_id; } $this->messenger->addError(t('You do not have permission to post a comment.')); $this->messenger->addError($this->t('You do not have permission to post a comment.')); // If this is a new top-level comment (not a reply to another comment so // no $pid), replace the comment form with the error message. if (empty($pid)) { Loading src/FieldSettingsHelper.php +3 −6 Original line number Diff line number Diff line Loading @@ -10,9 +10,7 @@ use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Field\FormatterPluginManager; /** * Class FieldSettingsHelper. * * @package Drupal\ajax_comments * Provides various methods to work with the fields. */ class FieldSettingsHelper { Loading @@ -31,7 +29,7 @@ class FieldSettingsHelper { protected $fieldFormatterManager; /** * AjaxCommentsFieldSettings constructor. * FieldSettingsHelper constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. Loading Loading @@ -154,8 +152,7 @@ class FieldSettingsHelper { * entity view mode. * * @return bool * Whether or not ajax comments is enabled on the comment field's display * settings. * Whether ajax comments is enabled on the comment field's display settings. */ public function isEnabled(FormatterInterface $comment_formatter) { return $comment_formatter->getThirdPartySetting('ajax_comments', 'enable_ajax_comments', '1'); Loading src/Form/AjaxCommentsDeleteForm.php +0 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides ajax enhancements to core Comment delete form. * * @package Drupal\ajax_comments */ class AjaxCommentsDeleteForm extends DeleteForm { Loading Loading
ajax_comments.module +16 −19 Original line number Diff line number Diff line Loading @@ -6,28 +6,20 @@ */ use Drupal\ajax_comments\Controller\AjaxCommentsController; use Drupal\ajax_comments\FieldSettingsHelper; use Drupal\ajax_comments\Utility; use Drupal\comment\CommentInterface; use Drupal\node\NodeInterface; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Html; use Drupal\Core\Ajax; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\AlertCommand; use Drupal\Core\Ajax\CloseDialogCommand; use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatch; use Symfony\Component\HttpFoundation\Request; /** * Implements hook_comment_links_alter(). Loading @@ -35,8 +27,7 @@ use Symfony\Component\HttpFoundation\Request; * For entity bundles with ajax comments enabled, alter the comment link * classes to allow ajax behaviors to be attached. */ function ajax_comments_comment_links_alter(array &$links, CommentInterface &$entity, array &$context) { $request = \Drupal::request(); function ajax_comments_comment_links_alter(array &$links, CommentInterface $entity, array &$context) { /** @var \Drupal\ajax_comments\FieldSettingsHelper $field_settings_helper */ $field_settings_helper = \Drupal::service('ajax_comments.field_settings_helper'); $comment_formatter = $field_settings_helper->getFieldFormatterFromComment($entity, $context['view_mode']); Loading Loading @@ -135,7 +126,11 @@ function ajax_comments_node_links_alter(array &$node_links, NodeInterface $node, $links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); foreach ($links as $link_name => $link) { $field_name = substr($link_name, strlen('comment__')); $classes = ['js-use-ajax-comments', 'js-ajax-comments-reply', 'js-ajax-comments-reply-' . $node->id() . '-' . $field_name . '-0']; $classes = [ 'js-use-ajax-comments', 'js-ajax-comments-reply', 'js-ajax-comments-reply-' . $node->id() . '-' . $field_name . '-0', ]; if (!empty($link['#links']['comment-add'])) { if (empty($link['#links']['comment-add']['attributes']['class'])) { $links[$link_name]['#links']['comment-add']['attributes']['class'] = $classes; Loading Loading @@ -218,7 +213,10 @@ function ajax_comments_form_comment_form_alter(&$form, FormStateInterface $form_ // If the user is on the standalone comment reply page, it means JavaScript // is disabled or the ajax functionality is not working. Do not proceed with // the form alter. if (in_array($current_route->getRouteName(), ['comment.reply', 'entity.comment.edit_form'])) { if (in_array($current_route->getRouteName(), [ 'comment.reply', 'entity.comment.edit_form', ])) { return; } Loading @@ -226,7 +224,6 @@ function ajax_comments_form_comment_form_alter(&$form, FormStateInterface $form_ $comment = $form_state->getFormObject()->getEntity(); /** @var \Drupal\Core\Entity\EntityInterface $commented_entity */ $commented_entity = $comment->getCommentedEntity(); $field_name = $comment->getFieldName(); // Check to see if this node type uses ajax comments. $comment_formatter = $field_settings_helper->getFieldFormatterFromComment($comment, 'full'); Loading Loading @@ -299,11 +296,11 @@ function ajax_comments_preprocess_pager(&$variables) { // Query parameters are added in // core/includes/pager.inc in the template_preprocess_pager(), // where pager_query_add_page() calls pager_get_query_parameters(), // which will pick up the ajax wrapper format from the ajax request, which breaks // the pager. // Unfortunately there is no way to remove this parameter before it is rendered to text, // so this preprocess function removes the parameter with string replacement. // which will pick up the ajax wrapper format from the ajax request, // which breaks the pager. // Unfortunately there is no way to remove this parameter before it is // rendered to text, so this preprocess function removes the parameter with // string replacement. // Remove ajax wrapper format from first, previous. if (isset($variables['items']['first'])) { $variables['items']['first']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['first']['href']); Loading
src/Ajax/ajaxCommentsScrollToElementCommand.php→src/Ajax/AjaxCommentsScrollToElementCommand.php +2 −7 Original line number Diff line number Diff line <?php /** * @file * Contains \Drupal\ajax_comments\Ajax\ajaxCommentsScrollToElementCommand. */ namespace Drupal\ajax_comments\Ajax; use Drupal\Core\Ajax\CommandInterface; Loading @@ -14,7 +9,7 @@ use Drupal\Core\Ajax\CommandInterface; * * @ingroup ajax */ class ajaxCommentsScrollToElementCommand Implements CommandInterface { class AjaxCommentsScrollToElementCommand implements CommandInterface { /** * The CSS selector for the element. Loading @@ -27,7 +22,7 @@ class ajaxCommentsScrollToElementCommand Implements CommandInterface { * Constructs a ajaxCommentsScrollToElementCommand object. * * @param string $selector * * The selector for the command. */ public function __construct($selector) { $this->selector = $selector; Loading
src/Controller/AjaxCommentsController.php +49 −20 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ use Drupal\Core\Ajax\InvokeCommand; use Drupal\Core\Ajax\PrependCommand; use Drupal\Core\Ajax\RemoveCommand; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; Loading Loading @@ -72,6 +73,20 @@ class AjaxCommentsController extends ControllerBase { */ protected $messenger; /** * The Configuration Factory service. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** * The current user account. * * @var \Drupal\Core\Session\AccountInterface */ protected $currentUser; /** * Constructs a AjaxCommentsController object. * Loading @@ -87,14 +102,17 @@ class AjaxCommentsController extends ControllerBase { * The TempStore service. * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The Messenger service. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The Configuration Factory service. */ public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, RendererInterface $renderer, RouterInterface $router, TempStore $temp_store, MessengerInterface $messenger) { public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, RendererInterface $renderer, RouterInterface $router, TempStore $temp_store, MessengerInterface $messenger, ConfigFactoryInterface $config_factory) { $this->entityTypeManager = $entity_type_manager; $this->currentUser = $current_user; $this->renderer = $renderer; $this->router = $router; $this->tempStore = $temp_store; $this->messenger = $messenger; $this->configFactory = $config_factory; } /** Loading @@ -107,7 +125,8 @@ class AjaxCommentsController extends ControllerBase { $container->get('renderer'), $container->get('router.no_access_checks'), $container->get('ajax_comments.temp_store'), $container->get('messenger') $container->get('messenger'), $container->get('config.factory') ); } Loading Loading @@ -228,7 +247,7 @@ class AjaxCommentsController extends ControllerBase { * The modified ajax response. */ protected function addMessages(Request $request, AjaxResponse $response, $selector = '', $position = 'prepend') { $settings = \Drupal::config('ajax_comments.settings'); $settings = $this->configFactory->get('ajax_comments.settings'); $notify = $settings->get('notify'); if ($notify || !empty($this->messenger->messagesByType(MessengerInterface::TYPE_ERROR))) { Loading Loading @@ -332,15 +351,17 @@ class AjaxCommentsController extends ControllerBase { $form = $this->entityFormBuilder()->getForm($comment); $response->addCommand(new AfterCommand(static::getCommentSelectorPrefix() . $comment->id(), $form)); // TODO: Get this custom ajax command working later. // @todo Get this custom ajax command working later. // @codingStandardsIgnoreStart // if (\Drupal::config('ajax_comments.settings')->get('enable_scroll')) { // $response->addCommand(new ajaxCommentsScrollToElementCommand('.ajax-comments-reply-form-' . $comment->getCommentedEntityId() . '-' . $comment->get('pid')->target_id . '-' . $comment->id())); // } // @codingStandardsIgnoreEnd // Don't delete the tempStore variables here; we need them // to persist for the save() method below, where the form returned // here will be submitted. // Instead, return the response without calling $this->tempStore->deleteAll(). // Instead, return the response without calling // $this->tempStore->deleteAll(). return $response; } else { Loading Loading @@ -416,7 +437,7 @@ class AjaxCommentsController extends ControllerBase { $cid = $this->tempStore->getCid(); // Try to insert the message above the new comment. if (!empty($cid) && !$errors && \Drupal::currentUser()->hasPermission('skip comment approval')) { if (!empty($cid) && !$errors && $this->currentUser()->hasPermission('skip comment approval')) { $selector = static::getCommentSelectorPrefix() . $cid; $response = $this->addMessages( $request, Loading Loading @@ -454,10 +475,10 @@ class AjaxCommentsController extends ControllerBase { // core/misc/drupal.js is reinserted into the DOM, the following line of // code will execute, causing Drupal.attachBehaviors() to run on the entire // document, and reattach behaviors to DOM elements that already have them: // @code // @codingStandardsIgnoreStart // // Attach all behaviors. // domready(function () { Drupal.attachBehaviors(document, drupalSettings); }); // @endcode // @codingStandardsIgnoreEnd $attachments = $response->getAttachments(); // Need to have only 'core/drupalSettings' in the asset library list. // If neither 'core/drupalSettings', nor a library with a dependency on it, Loading Loading @@ -494,10 +515,17 @@ class AjaxCommentsController extends ControllerBase { if ($cid != 0) { // Show the hidden anchor. $response->addCommand(new InvokeCommand('a#comment-' . $cid, 'show', [200, 'linear'])); $response->addCommand(new InvokeCommand( 'a#comment-' . $cid, 'show', [200, 'linear'] ) ); // Show the hidden comment. $response->addCommand(new InvokeCommand(static::getCommentSelectorPrefix() . $cid, 'show', [200, 'linear'])); $response->addCommand(new InvokeCommand( static::getCommentSelectorPrefix() . $cid, 'show', [200, 'linear'] ) ); } // Remove the form. Loading Loading @@ -658,10 +686,10 @@ class AjaxCommentsController extends ControllerBase { // core/misc/drupal.js is reinserted into the DOM, the following line of // code will execute, causing Drupal.attachBehaviors() to run on the entire // document, and reattach behaviors to DOM elements that already have them: // @code // @codingStandardsIgnoreStart // // Attach all behaviors. // domready(function () { Drupal.attachBehaviors(document, drupalSettings); }); // @endcode // @codingStandardsIgnoreEnd $attachments = $response->getAttachments(); // Need to have only 'core/drupalSettings' in the asset library list. // If neither 'core/drupalSettings', nor a library with a dependency on it, Loading Loading @@ -738,7 +766,8 @@ class AjaxCommentsController extends ControllerBase { // Don't delete the tempStore variables here; we need them // to persist for the saveReply() method, where the form returned // here will be submitted. // Instead, return the response without calling $this->tempStore->deleteAll(). // Instead, return the response without calling // $this->tempStore->deleteAll(). return $response; } else { Loading Loading @@ -794,21 +823,21 @@ class AjaxCommentsController extends ControllerBase { // Build a dummy comment entity to pass to $this->save(), which will use // it to rebuild the comment entity form to trigger form submission. // @code // @codingStandardsIgnoreStart // $form = $this->entityFormBuilder()->getForm($comment, 'default', ['editing' => TRUE]); // @endcode // @codingStandardsIgnoreEnd // Note that this approach will correctly process the form submission // even though we are passing in an empty, dummy comment, because two steps // later in the call stack, \Drupal\Core\Form\FormBuilder::buildForm() is // called, and it checks the current request object for form submission // values if there aren't any in the form state, yet: // @code // @codingStandardsIgnoreStart // $input = $form_state->getUserInput(); // if (!isset($input)) { // $input = $form_state->isMethodType('get') ? $request->query->all() : $request->request->all(); // $form_state->setUserInput($input); // } // @endcode // @codingStandardsIgnoreEnd // This approach is very similar to the one taken in // \Drupal\comment\CommentLazyBuilders::renderForm(). $comment = $this->entityTypeManager()->getStorage('comment')->create([ Loading Loading @@ -836,7 +865,7 @@ class AjaxCommentsController extends ControllerBase { * (optional) Some comments are replies to other comments. In those cases, * $pid is the parent comment's comment ID. Defaults to NULL. * * @return \Drupal\Core\Ajax\AjaxResponse $response * @return \Drupal\Core\Ajax\AjaxResponse * The ajax response, if access is denied. */ public function replyAccess(Request $request, AjaxResponse $response, EntityInterface $entity, $field_name, $pid = NULL) { Loading @@ -855,7 +884,7 @@ class AjaxCommentsController extends ControllerBase { if (empty($selector)) { $selector = $wrapper_html_id; } $this->messenger->addError(t('You do not have permission to post a comment.')); $this->messenger->addError($this->t('You do not have permission to post a comment.')); // If this is a new top-level comment (not a reply to another comment so // no $pid), replace the comment form with the error message. if (empty($pid)) { Loading
src/FieldSettingsHelper.php +3 −6 Original line number Diff line number Diff line Loading @@ -10,9 +10,7 @@ use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Field\FormatterPluginManager; /** * Class FieldSettingsHelper. * * @package Drupal\ajax_comments * Provides various methods to work with the fields. */ class FieldSettingsHelper { Loading @@ -31,7 +29,7 @@ class FieldSettingsHelper { protected $fieldFormatterManager; /** * AjaxCommentsFieldSettings constructor. * FieldSettingsHelper constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. Loading Loading @@ -154,8 +152,7 @@ class FieldSettingsHelper { * entity view mode. * * @return bool * Whether or not ajax comments is enabled on the comment field's display * settings. * Whether ajax comments is enabled on the comment field's display settings. */ public function isEnabled(FormatterInterface $comment_formatter) { return $comment_formatter->getThirdPartySetting('ajax_comments', 'enable_ajax_comments', '1'); Loading
src/Form/AjaxCommentsDeleteForm.php +0 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides ajax enhancements to core Comment delete form. * * @package Drupal\ajax_comments */ class AjaxCommentsDeleteForm extends DeleteForm { Loading