You are here

class HelpMessageHelper in Acquia Lift Connector 8

Same name and namespace in other branches
  1. 8.4 src/Service/Helper/HelpMessageHelper.php \Drupal\acquia_lift\Service\Helper\HelpMessageHelper
  2. 8.3 src/Service/Helper/HelpMessageHelper.php \Drupal\acquia_lift\Service\Helper\HelpMessageHelper

Hierarchy

Expanded class hierarchy of HelpMessageHelper

1 file declares its use of HelpMessageHelper
HelpMessageHelperTest.php in tests/src/Unit/Service/Helper/HelpMessageHelperTest.php
Contains \Drupal\Tests\acquia_lift\Service\Helper\HelpMessageHelperTest.
1 string reference to 'HelpMessageHelper'
acquia_lift.services.yml in ./acquia_lift.services.yml
acquia_lift.services.yml
1 service uses HelpMessageHelper
acquia_lift.service.helper.help_message_helper in ./acquia_lift.services.yml
Drupal\acquia_lift\Service\Helper\HelpMessageHelper

File

src/Service/Helper/HelpMessageHelper.php, line 14
Contains \Drupal\acquia_lift\Service\Helper\HelpMessageHelper.

Namespace

Drupal\acquia_lift\Service\Helper
View source
class HelpMessageHelper {

  /**
   * Acquia Lift credential settings.
   *
   * @var array
   */
  private $credentialSettings;

  /**
   * Link generator.
   *
   * @var \Drupal\Core\Utility\LinkGeneratorInterface
   */
  private $linkGenerator;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
   *   The link generator.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LinkGeneratorInterface $link_generator) {
    $this->credentialSettings = $config_factory
      ->get('acquia_lift.settings')
      ->get('credential');
    $this->linkGenerator = $link_generator;
  }

  /**
   * Get help message (by route name).
   *
   * @param string $route_name
   *   Route name.
   *
   * @return string
   *   The help message.
   */
  public function getMessage($route_name) {
    switch ($route_name) {
      case 'help.page.acquia_lift':
      case 'acquia_lift.admin_settings_form':
        $link_attributes = [
          'attributes' => [
            'target' => '_blank',
          ],
        ];

        // Generate Documentation link.
        $documentation_link_text = t('Documentation');
        $documentation_link_url = Url::fromUri('https://docs.acquia.com/lift/', $link_attributes);
        $documentation_external_link = $this->linkGenerator
          ->generate($documentation_link_text, $documentation_link_url);
        $help_message = t('You can find more info in ') . $documentation_external_link;

        // Generate Acquia Lift Web Admin link.
        if (!empty($this->credentialSettings['api_url'])) {
          $lift_web_link_text = t('Acquia Lift Web Admin');
          $lift_web_link_url = Url::fromUri('https://' . $this->credentialSettings['api_url'], $link_attributes);
          $lift_web_external_link = $this->linkGenerator
            ->generate($lift_web_link_text, $lift_web_link_url);
          $help_message .= t(', and control your web services settings at ') . $lift_web_external_link;
        }
        $help_message .= t('.');
        return $help_message;
    }
    return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HelpMessageHelper::$credentialSettings private property Acquia Lift credential settings.
HelpMessageHelper::$linkGenerator private property Link generator.
HelpMessageHelper::getMessage public function Get help message (by route name).
HelpMessageHelper::__construct public function Constructor.