class InaccessibleMenuLink extends MenuLinkBase (View source)

A menu link plugin for wrapping another menu link, in sensitive situations.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Provides dependency injection friendly methods for serialization.

Provides a trait for the messenger service.

Constants

DERIVATIVE_SEPARATOR

A string which is used to separate base plugin IDs from the derivative ID.

Properties

protected string $pluginId

The plugin_id.

from  PluginBase
protected array $pluginDefinition

The plugin implementation definition.

from  PluginBase
protected array $configuration

Configuration information passed into the plugin.

from  PluginBase
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected array $overrideAllowed

The list of definition values where an override is allowed.

from  MenuLinkBase
$wrappedLink

The wrapped menu link.

Methods

__construct(MenuLinkInterface $wrapped_link)

Constructs a new InaccessibleMenuLink.

string
getPluginId()

Gets the plugin_id of the plugin instance.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

bool
isConfigurable()

Determines if the plugin is configurable.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

int
getWeight()

Returns the weight of the menu link.

string
getMenuName()

Returns the menu name of the menu link.

string
getProvider()

Returns the provider (module name) of the menu link.

string
getParent()

Returns the plugin ID of the menu link's parent, or an empty string.

bool
isEnabled()

Returns whether the menu link is enabled (not hidden).

bool
isExpanded()

Returns whether the child menu links should always been shown.

bool
isResettable()

Returns whether this link can be reset.

bool
isTranslatable()

Returns whether this link can be translated.

bool
isDeletable()

Returns whether this link can be deleted.

array
getOptions()

Returns the options for this link.

array
getMetaData()

Returns any metadata for this link.

string
getRouteName()

Returns the route name, if available.

array
getRouteParameters()

Returns the route parameters, if available.

Url
getUrlObject(bool $title_attribute = TRUE)

Returns a URL object containing either the external path or route.

string
getFormClass()

Returns the name of a class that can build an editing form for this link.

Url|null
getDeleteRoute()

Returns route information for a route to delete the menu link.

Url|null
getEditRoute()

Returns route information for a custom edit form for the menu link.

Url|null
getTranslateRoute()

Returns route information for a route to translate the menu link.

deleteLink()

Deletes a menu link.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

string
getTitle()

Returns the localized title to be shown for this link.

string
getDescription()

Returns the description of the menu link.

array
updateLink(array $new_definition_values, bool $persist)

Updates the definition values for a menu link.

Details

__construct(MenuLinkInterface $wrapped_link)

Constructs a new InaccessibleMenuLink.

Parameters

MenuLinkInterface $wrapped_link

The menu link to wrap.

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

bool isConfigurable()

Determines if the plugin is configurable.

Return Value

bool

A boolean indicating whether the plugin is configurable.

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

int getWeight()

Returns the weight of the menu link.

Return Value

int

The weight of the menu link, 0 by default.

string getMenuName()

Returns the menu name of the menu link.

Return Value

string

The menu name of the menu link.

string getProvider()

Returns the provider (module name) of the menu link.

Return Value

string

The provider of the menu link.

string getParent()

Returns the plugin ID of the menu link's parent, or an empty string.

Return Value

string

The parent plugin ID.

bool isEnabled()

Returns whether the menu link is enabled (not hidden).

Return Value

bool

TRUE for enabled, FALSE otherwise.

bool isExpanded()

Returns whether the child menu links should always been shown.

Return Value

bool

TRUE for expanded, FALSE otherwise.

bool isResettable()

Returns whether this link can be reset.

In general, only links that store overrides using the menu_link.static.overrides service should return TRUE for this method.

Return Value

bool

TRUE if it can be reset, FALSE otherwise.

bool isTranslatable()

Returns whether this link can be translated.

Return Value

bool

TRUE if the link can be translated, FALSE otherwise.

bool isDeletable()

Returns whether this link can be deleted.

Return Value

bool

TRUE if the link can be deleted, FALSE otherwise.

array getOptions()

Returns the options for this link.

Return Value

array

An associative array of options.

array getMetaData()

Returns any metadata for this link.

Return Value

array

The metadata for the menu link.

string getRouteName()

Returns the route name, if available.

Return Value

string

The name of the route this menu link links to.

array getRouteParameters()

Returns the route parameters, if available.

Return Value

array

An array of parameter names and values.

Url getUrlObject(bool $title_attribute = TRUE)

Returns a URL object containing either the external path or route.

Parameters

bool $title_attribute

(optional) If TRUE, add the link description as the title attribute if the description is not empty.

Return Value

Url

A URL object containing either the external path or route.

string getFormClass()

Returns the name of a class that can build an editing form for this link.

To instantiate the form class, use an instance of the \Drupal\Core\DependencyInjection\ClassResolverInterface, such as from the class_resolver service. Then call the setMenuLinkInstance() method on the form instance with the menu link plugin instance.

Return Value

string

A class that implements \Drupal\Core\Menu\Form\MenuLinkFormInterface.

Url|null getDeleteRoute()

Returns route information for a route to delete the menu link.

Return Value

Url|null

A Url object, or NULL if there is no route (e.g. when the link is not deletable).

Url|null getEditRoute()

Returns route information for a custom edit form for the menu link.

Plugins should return a value here if they have a special edit form, or if they need to define additional local tasks, local actions, etc. that are visible from the edit form.

Return Value

Url|null

A Url object, or NULL if there is no route because there is no custom edit route for this instance.

Url|null getTranslateRoute()

Returns route information for a route to translate the menu link.

Return Value

Url|null

A Url object, or NULL if there is no route (e.g. when the link is not translatable).

Deletes a menu link.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::removeDefinition().

This method will only delete the link from any additional storage, but not from the plugin.manager.menu.link service.

Exceptions

PluginException

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

string getTitle()

Returns the localized title to be shown for this link.

Return Value

string

The title of the menu link.

string getDescription()

Returns the description of the menu link.

Return Value

string

The description of the menu link.

Updates the definition values for a menu link.

Depending on the implementation details of the class, not all definition values may be changed. For example, changes to the title of a static link will be discarded.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::updateDefinition().

Parameters

array $new_definition_values

The new values for the link definition. This will usually be just a subset of the plugin definition.

bool $persist

TRUE to have the link persist the changed values to any additional storage.

Return Value

array

The plugin definition incorporating any allowed changes.