I am trying to create the SkipLink Settings Plugin exactly like explained on
https://drupal-bootstrap.org/api/bootstrap/docs%21plugins%21Setting.md/g...

However, after creating the file /themes/mysubtheme/src/Plugin/Setting/mysubtheme/Accessibility/SkipLink.php, I always end up with this error:

Drupal\Component\Plugin\Exception\PluginException: Plugin (mysubtheme_skip_link_id) instance class "Drupal\mysubtheme\Plugin\Setting\mysubtheme\Accessibility\SkipLink" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (Line 97 in /var/www/vhosts/mysite.local/httpdocs/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).

This is my SkipLink.php:

<?php
namespace Drupal\mysubtheme\Plugin\Setting\mysubtheme\Accessibility\SkipLink;

use Drupal\bootstrap\Annotation\BootstrapSetting;
use Drupal\bootstrap\Plugin\Setting\SettingBase;
use Drupal\Core\Annotation\Translation;

/**
 * The "mysubtheme_skip_link_id" theme setting.
 *
 * @ingroup plugins_setting
 *
 * @BootstrapSetting(
 *   id = "mysubtheme_skip_link_id",
 *   type = "textfield",
 *   title = @Translation("Anchor ID for the ""skip link"""),
 *   defaultValue = "main-content",
 *   description = @Translation("Specify the HTML ID of the element that the accessible-but-hidden ""skip link"" should link to. (<a href="":link"" target=""_blank"">Read more about skip links</a>.)",
     arguments = { ":link"  = "http://drupal.org/node/467976" }),
 *   groups = {
 *     "mysubtheme" = "MySubTheme",
 *     "accessibility" = @Translation("Accessibility"),
 *   },
 * )
 */
class SkipLink extends SettingBase {}

I went through all steps from scratch for the third time now.

Any hints what could be wrong?

Comments

designcrs created an issue. See original summary.

markhalliwell’s picture

Version: 8.x-3.1 » 8.x-3.x-dev
Component: Plugin System » Documentation
Category: Support request » Bug report
Priority: Normal » Minor

The namespace is wrong.

You don't put the class name at the end, it's what sits underneath the namespace.

It should just be

namespace Drupal\mysubtheme\Plugin\Setting\mysubtheme\Accessibility;

I'll commit a fix to the docs shortly.

markhalliwell’s picture

Title: @BootstrapSetting SkipLink Example » @BootstrapSetting example has class name is in namespace

  • markcarver committed 5973fad on 8.x-3.x
    Issue #2855542 by designcrs, markcarver: @BootstrapSetting example has...
markhalliwell’s picture

Status: Active » Fixed
designcrs’s picture

Works perfectly now! Thank you so much!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.