You are here

class NodePromotion in Fasttoggle 8.2

Abstract interface for settings. Plugin strings are used for quick filtering without the need to instantiate the class.

Plugin annotation


@Plugin(
  entityType = "node",
  name = "promoted",
  description = "Promoted <small>(promoted/not promoted)</small>",
  id = "node_promoted",
  group = "node_core",
  weight = 20,
  default = false,
  base_formatter = "Drupal\fasttoggle\Plugin\Field\FieldFormatter\BooleanFormatter",
  attributes = {
   "promoted" = "Promoted",
  },
  labels = {
    FASTTOGGLE_LABEL_ACTION = {
      0 = @Translation("promote"),
      1 = @Translation("demote"),
    },
    FASTTOGGLE_LABEL_STATUS = {
      0 = @Translation("not promoted"),
      1 = @Translation("promoted"),
    },
  },
)

Hierarchy

Expanded class hierarchy of NodePromotion

File

src/Plugin/Setting/NodePromotion.php, line 46
Fasttoggle Node Promotion

Namespace

Drupal\fasttoggle\Plugin\Setting
View source
class NodePromotion extends NodeCore implements SettingInterface {
  use SettingTrait;

  /**
   * Access control function.
   *
   * @param $node
   *   The node against which to check (un)publish permission.
   *
   * @return boolean
   *   Whether the user is allowed to (un)publish the node.
   */
  public function mayEditSetting() {
    $user = \Drupal::currentUser();
    $config = \Drupal::config('fasttoggle.settings');
    $sitewide = $config
      ->get('node_core_promoted');
    $result = AccessResult::allowedIf($sitewide)
      ->addCacheableDependency($config)
      ->andIf(AccessResult::allowedIfHasPermission($user, [
      "override {$this->object->getType()} promoted option",
      'promote posts',
    ], 'OR'));
    return $result;
  }

  /**
   * Return whether this setting matches the provided field definition.
   *
   * @param $definition
   *   The field definition for which a match is being sought.
   *
   * @return boolean
   *   Whether this plugin handles the definition.
   */
  public static function matches($definition) {
    $has_get = is_callable(array(
      $definition,
      'get',
    ));
    $entity = $has_get ? $definition
      ->get('entity_type') : $definition
      ->getProvider();
    return $entity == 'node' && $definition
      ->getName() == 'promote';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractSettingObject::$object protected property The object being managed.
AbstractSettingObject::get_object public function Get the object instance. Overrides SettingObjectInterface::get_object
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 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
node::get_id public function Object ID. Overrides AbstractSettingObject::get_id
node::get_title public function Object title. Overrides AbstractSettingObject::get_title
node::get_type public function Object subtype machine name. Overrides AbstractSettingObject::get_type
node::mayEditEntity public function Access. Overrides AbstractSettingObject::mayEditEntity
node::objectMatches public function Matches an object? Overrides SettingObjectInterface::objectMatches
node::save public function Save function. Overrides AbstractSettingObject::save
node::setObject public function Set the node object. Overrides AbstractSettingObject::setObject
NodeCore::groupMatches public static function Return whether this setting matches the provided field definition. Overrides SettingGroupInterface::groupMatches
NodeCore::mayEditGroup public function Access. Overrides SettingGroupInterface::mayEditGroup
NodePromotion::matches public static function Return whether this setting matches the provided field definition. Overrides SettingInterface::matches
NodePromotion::mayEditSetting public function Access control function. Overrides SettingTrait::mayEditSetting
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SettingTrait::configSettingKeys public function Keys for config settings.
SettingTrait::formatter public function Get the markup we modify.
SettingTrait::getHumanReadableValueList public function Get a plain text list of human readable labels for the setting, in the order used.
SettingTrait::getSitewideSettingFormElements public static function Get an array of sitewide setting form elements for this object type.
SettingTrait::getValueList public function Get a list of actual values for the setting, in the order used. 1
SettingTrait::get_field function Retrieve the FieldItem for a setting.
SettingTrait::get_labels public function Get labels (fallback function if a template is used (eg roles)
SettingTrait::get_value function Retrieve the current value of the setting. 1
SettingTrait::mayEdit public function Write access check.
SettingTrait::nextValue public function Move to the next setting value.
SettingTrait::previousValue public function Move to the previous setting value and save it.
SettingTrait::render_array public function Return a render array for an instance of this setting.
SettingTrait::setField function Set a custom field name (eg fields on nodes).
SettingTrait::settingForm public function Return the sitewide form element for this setting. 1
SettingTrait::set_value function Modify the setting. 1
SettingTrait::trait_constructor public function Allow access to the trait constructor if the setting also implements one.
SettingTrait::__construct public function 1
SettingTrait::__get public function Retrieve the object type that can be modified by this setting.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.