You are here

class CommentFlagType in Flag 8.4

Provides a flag type for comments.

Plugin annotation


@FlagType(
  id = "entity:comment",
  title = @Translation("Comment"),
  entity_type = "comment",
  provider = "comment"
)

Hierarchy

Expanded class hierarchy of CommentFlagType

File

src/Plugin/Flag/CommentFlagType.php, line 17

Namespace

Drupal\flag\Plugin\Flag
View source
class CommentFlagType extends EntityFlagType {

  /**
   * {@inheritdoc}
   */
  protected function getExtraPermissionsOptions() {
    $options = parent::getExtraPermissionsOptions();
    $options['parent_owner'] = $this
      ->t("Permissions based on ownership of a comment's parent entity.");
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function actionPermissions(FlagInterface $flag) {
    $permissions = parent::actionPermissions($flag);
    if (!empty($this->configuration['extra_permissions'])) {
      foreach ($this->configuration['extra_permissions'] as $option) {
        switch ($option) {

          // The 'owner' case is handled by the parent method.
          case 'parent_owner':

            // Define additional permissions.
            $permissions['flag ' . $flag
              ->id() . ' comments on own parent entities'] = [
              'title' => $this
                ->t('Flag %flag_title comments on own parent entities', [
                '%flag_title' => $flag
                  ->label(),
              ]),
            ];
            $permissions['unflag ' . $flag
              ->id() . ' comments on own parent entities'] = [
              'title' => $this
                ->t('Unflag %flag_title on own parent entities', [
                '%flag_title' => $flag
                  ->label(),
              ]),
            ];
            $permissions['flag ' . $flag
              ->id() . ' comments on other parent entities'] = [
              'title' => $this
                ->t("Flag %flag_title on others' parent entities", [
                '%flag_title' => $flag
                  ->label(),
              ]),
            ];
            $permissions['unflag ' . $flag
              ->id() . ' comments on other parent entities'] = [
              'title' => $this
                ->t("Unflag %flag_title on others' parent entities", [
                '%flag_title' => $flag
                  ->label(),
              ]),
            ];
            break;
        }
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommentFlagType::actionPermissions public function Returns the permissions available to this flag type. Overrides EntityFlagType::actionPermissions
CommentFlagType::getExtraPermissionsOptions protected function Defines options for extra permissions. Overrides EntityFlagType::getExtraPermissionsOptions
EntityFlagType::$entityType protected property The entity type defined in plugin definition.
EntityFlagType::$entityTypeManager protected property The entity type manager.
EntityFlagType::actionAccess public function Checks whether a user has permission to flag/unflag or not. Overrides FlagTypeBase::actionAccess 3
EntityFlagType::buildConfigurationForm public function Provides a form for this action link plugin settings. Overrides FlagTypeBase::buildConfigurationForm 1
EntityFlagType::create public static function Creates an instance of the plugin. Overrides FlagTypeBase::create
EntityFlagType::defaultConfiguration public function Gets default configuration for this plugin. Overrides FlagTypeBase::defaultConfiguration 1
EntityFlagType::getExtraPermissionsOwner protected function Defines permissions for the 'owner' set of additional action permissions. 1
EntityFlagType::isAddEditForm public function Determines if the given form operation is add or edit. 1
EntityFlagType::isFlaggableOwnable protected function Determines if the flaggable associated with the flag supports ownership. 1
EntityFlagType::showAsField public function Returns the show as field setting.
EntityFlagType::showContextualLink public function Returns the show on contextual link setting.
EntityFlagType::showInLinks public function Return the show in links setting given a view mode.
EntityFlagType::showOnForm public function Returns the show on form setting.
EntityFlagType::submitConfigurationForm public function Handles the form submit for this action link plugin. Overrides FlagTypeBase::submitConfigurationForm 1
EntityFlagType::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides FlagTypeBase::__construct
FlagTypeBase::$moduleHandler protected property The module handler.
FlagTypeBase::calculateDependencies public function
FlagTypeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
FlagTypeBase::hasExtraPermission protected function Determines whether the flag is set to have the extra permissions set.
FlagTypeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
FlagTypeBase::validateConfigurationForm public function Handles the validation for the action link plugin settings form. Overrides PluginFormInterface::validateConfigurationForm
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.
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.