You are here

function _fasttoggle_create_comment_link in Fasttoggle 8.3

Create fastoggle comment action link function.

1 call to _fasttoggle_create_comment_link()
fasttoggle_comment_links_alter in ./fasttoggle.module
Implements hook_comment_links_alter().

File

./fasttoggle.module, line 79
Main file for the fasttoggle module.

Code

function _fasttoggle_create_comment_link(CommentInterface $entity, $toggle, $link_name) {
  $config = \Drupal::config('fasttoggle.settings');
  $label_style = $config
    ->get('label_style');
  switch ($toggle) {
    case 'status':
      switch ($label_style) {
        case 0:
          $entity
            ->isPublished() ? $link_title = t('Published') : ($link_title = t('Not published'));
          break;
        case 1:
          $entity
            ->isPublished() ? $link_title = t('Unpublish') : ($link_title = t('Publish'));
          break;
      }
      break;
  }
  $link[$link_name] = [
    'title' => $link_title,
    'url' => Url::fromUserInput('/fasttoggle/comment/' . $entity
      ->id() . '/' . $toggle),
    'attributes' => [
      'class' => [
        'use-ajax',
        'fasttoggle-comment-' . $entity
          ->id() . '-' . $toggle,
      ],
    ],
  ];
  return $link[$link_name];
}