You are here

class GetValueCommand in Config Pages 8.2

Same name and namespace in other branches
  1. 8.3 src/Command/GetValueCommand.php \Drupal\config_pages\Command\GetValueCommand

Class for a Drupal command to works with ConfigPages.

@DrupalCommand ( extension="config_pages", extensionType="module" )

Hierarchy

  • class \Drupal\config_pages\Command\GetValueCommand extends \Drupal\Console\Core\Command\ContainerAwareCommand

Expanded class hierarchy of GetValueCommand

1 string reference to 'GetValueCommand'
console.services.yml in ./console.services.yml
console.services.yml
1 service uses GetValueCommand
config_pages.config_pages_get_value in ./console.services.yml
Drupal\config_pages\Command\GetValueCommand

File

src/Command/GetValueCommand.php, line 20

Namespace

Drupal\config_pages\Command
View source
class GetValueCommand extends ContainerAwareCommand {

  /**
   * Drupal logger.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * Constructs a new GetValueCommand object.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory
   *   Logger factory.
   */
  public function __construct(LoggerChannelFactoryInterface $loggerChannelFactory) {
    $this->logger = $loggerChannelFactory
      ->get('config_pages');
    parent::__construct();
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this
      ->setName('config_pages:get_value')
      ->setDescription($this
      ->trans('commands.config_pages.get_value.description'))
      ->addArgument('bundle', InputArgument::REQUIRED, $this
      ->trans('commands.user.login.url.options.bundle'), NULL)
      ->addArgument('field_name', InputArgument::REQUIRED, $this
      ->trans('commands.user.login.url.options.field_name'), NULL)
      ->addArgument('context', InputArgument::OPTIONAL, $this
      ->trans('commands.user.login.url.options.context'), NULL)
      ->setAliases([
      'cpgfv',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $bundle = $input
      ->getArgument('bundle');
    $field_name = $input
      ->getArgument('field_name');
    $context = $input
      ->getArgument('context');
    try {
      $config_page = config_pages_config($bundle, $context);
      if (!empty($config_page)) {
        $output
          ->writeln($config_page
          ->get($field_name)->value);
      }
    } catch (\Exception $e) {
      $this->logger
        ->error($e
        ->getMessage());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GetValueCommand::$logger protected property Drupal logger.
GetValueCommand::configure protected function
GetValueCommand::execute protected function
GetValueCommand::__construct public function Constructs a new GetValueCommand object.