class NodeDateArgumentDefaultPluginBase

Same name and namespace in other branches
  1. 11.x core/modules/node/src/Plugin/views/argument_default/NodeDateArgumentDefaultPluginBase.php \Drupal\node\Plugin\views\argument_default\NodeDateArgumentDefaultPluginBase

Provides a base class for node date values.

Hierarchy

Expanded class hierarchy of NodeDateArgumentDefaultPluginBase

File

core/modules/node/src/Plugin/views/argument_default/NodeDateArgumentDefaultPluginBase.php, line 17

Namespace

Drupal\node\Plugin\views\argument_default
View source
abstract class NodeDateArgumentDefaultPluginBase extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
  
  /**
   * Constructs a new NodeDateArgumentDefaultPluginBase instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   The route match.
   * @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
   *   The date formatter service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected RouteMatchInterface $routeMatch, protected DateFormatterInterface $dateFormatter) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : static {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('current_route_match'), $container->get('date.formatter'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getArgument() : string|bool {
    // Return a time value from the current node if available.
    if (($node = $this->routeMatch
      ->getParameter('node')) && $node instanceof NodeInterface) {
      // The Date argument handlers provide their own format strings, otherwise
      // use a default.
      $format = $this->argument instanceof Date ? $this->argument
        ->getArgFormat() : 'Y-m-d';
      return $this->dateFormatter
        ->format($this->getNodeDateValue($node), 'custom', $format);
    }
    return FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [
      'url',
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }
  
  /**
   * Gets a timestamp value from the passed node.
   *
   * @param \Drupal\node\NodeInterface $node
   *   The node to get the timestamp value from.
   *
   * @return int
   *   A timestamp value from a node field.
   */
  abstract protected function getNodeDateValue(NodeInterface $node) : int;

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ArgumentDefaultPluginBase::$argument protected property The argument handler instance associated with this plugin.
ArgumentDefaultPluginBase::$option_name public property The option name.
ArgumentDefaultPluginBase::access public function Determine if the administrator has the privileges to use this plugin.
ArgumentDefaultPluginBase::buildOptionsForm public function Provide the default form for setting options. Overrides PluginBase::buildOptionsForm
ArgumentDefaultPluginBase::checkAccess protected function Disables the given option if the user does not have access.
ArgumentDefaultPluginBase::defineOptions protected function Retrieve the options when this is a new access control plugin. Overrides PluginBase::defineOptions
ArgumentDefaultPluginBase::getCacheTags public function
ArgumentDefaultPluginBase::setArgument public function Sets the parent argument this plugin is associated with.
ArgumentDefaultPluginBase::submitOptionsForm public function Provide the default form for submitting options. Overrides PluginBase::submitOptionsForm
ArgumentDefaultPluginBase::validateOptionsForm public function Provide the default form for validating options. Overrides PluginBase::validateOptionsForm
AutowiredInstanceTrait::createInstanceAutowired public static function Instantiates a new instance of the implementing class using autowiring.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function
DependencySerializationTrait::__wakeup public function
MessengerTrait::$messenger protected property The messenger.
MessengerTrait::messenger public function Gets the messenger.
MessengerTrait::setMessenger public function Sets the messenger.
NodeDateArgumentDefaultPluginBase::create public static function Instantiates a new instance of the implementing class using autowiring. Overrides PluginBase::create
NodeDateArgumentDefaultPluginBase::getArgument public function Return the default argument. Overrides ArgumentDefaultPluginBase::getArgument
NodeDateArgumentDefaultPluginBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
NodeDateArgumentDefaultPluginBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
NodeDateArgumentDefaultPluginBase::getNodeDateValue abstract protected function Gets a timestamp value from the passed node.
NodeDateArgumentDefaultPluginBase::__construct public function Constructs a new NodeDateArgumentDefaultPluginBase instance. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$definition public property Plugins' definition.
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin ID.
PluginBase::$position public property The handler position.
PluginBase::$renderer protected property Stores the render API renderer.
PluginBase::$usesOptions protected property Denotes whether the plugin has an additional options form.
PluginBase::$view public property The top object of a view.
PluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::destroy public function Clears a plugin. Overrides ViewsPluginInterface::destroy
PluginBase::doFilterByDefinedOptions protected function Do the work to filter out stored options depending on the defined options.
PluginBase::filterByDefinedOptions public function Filter out stored options depending on the defined options. Overrides ViewsPluginInterface::filterByDefinedOptions
PluginBase::getAvailableGlobalTokens public function Returns an array of available token replacements. Overrides ViewsPluginInterface::getAvailableGlobalTokens
PluginBase::getBaseId public function
PluginBase::getDerivativeId public function
PluginBase::getPluginDefinition public function
PluginBase::getPluginId public function
PluginBase::getProvider public function Returns the plugin provider. Overrides ViewsPluginInterface::getProvider
PluginBase::getRenderer protected function Returns the render API renderer.
PluginBase::globalTokenForm public function Adds elements for available core tokens to a form. Overrides ViewsPluginInterface::globalTokenForm
PluginBase::globalTokenReplace public function Returns a string with any core tokens replaced. Overrides ViewsPluginInterface::globalTokenReplace
PluginBase::INCLUDE_ENTITY constant Include entity row languages when listing languages.
PluginBase::INCLUDE_NEGOTIATED constant Include negotiated languages when listing languages.
PluginBase::init public function Initialize the plugin. Overrides ViewsPluginInterface::init
PluginBase::listLanguages protected function Makes an array of languages, optionally including special languages.
PluginBase::pluginTitle public function Return the human readable name of the display. Overrides ViewsPluginInterface::pluginTitle
PluginBase::preRenderAddFieldsetMarkup public static function Moves form elements into fieldsets for presentation purposes. Overrides ViewsPluginInterface::preRenderAddFieldsetMarkup
PluginBase::preRenderFlattenData public static function Flattens the structure of form elements. Overrides ViewsPluginInterface::preRenderFlattenData
PluginBase::query public function Add anything to the query that we might need to. Overrides ViewsPluginInterface::query
PluginBase::queryLanguageSubstitutions public static function Returns substitutions for Views queries for languages.
PluginBase::setOptionDefaults protected function Fills up the options of the plugin with defaults.
PluginBase::summaryTitle public function Returns the summary of the settings in the display. Overrides ViewsPluginInterface::summaryTitle
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. Overrides ViewsPluginInterface::themeFunctions
PluginBase::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
PluginBase::unpackOptions public function Unpacks options over our existing defaults. Overrides ViewsPluginInterface::unpackOptions
PluginBase::usesOptions public function Returns the usesOptions property. Overrides ViewsPluginInterface::usesOptions
PluginBase::validate public function Validate that the plugin is correct and can be saved. Overrides ViewsPluginInterface::validate
PluginBase::viewsTokenReplace protected function Replaces Views' tokens in a given string.
PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT constant Query string to indicate the site default language.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.