class MockLayoutBlockDeriver

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php \Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlockDeriver
  2. 10 core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php \Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlockDeriver
  3. 11.x core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php \Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlockDeriver

Mock implementation of DeriverInterface for the mock layout block plugin.

Hierarchy

Expanded class hierarchy of MockLayoutBlockDeriver

See also

\Drupal\plugin_test\Plugin\MockBlockManager

File

core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php, line 13

Namespace

Drupal\plugin_test\Plugin\plugin_test\mock_block
View source
class MockLayoutBlockDeriver implements DeriverInterface {
    use StringTranslationTrait;
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
        $derivatives = $this->getDerivativeDefinitions($base_plugin_definition);
        if (isset($derivatives[$derivative_id])) {
            return $derivatives[$derivative_id];
        }
        return NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        // This isn't strictly necessary, but it helps reduce clutter in
        // DerivativePluginTest::testDerivativeDecorator()'s $expected variable.
        // Since derivative definitions don't need further deriving, we remove this
        // key from the returned definitions.
        unset($base_plugin_definition['deriver']);
        $derivatives = [
            // Adding a NULL key signifies that the base plugin may also be used in
            // addition to the derivatives. In this case, we allow the administrator
            // to add a generic layout block to the page.
NULL => $base_plugin_definition,
            // We also allow them to add a customized one. Here, we just mock the
            // customized one, but in a real implementation, this would be fetched
            // from some \Drupal::config() object.
'foo' => [
                'label' => $this->t('Layout Foo'),
            ] + $base_plugin_definition,
        ];
        return $derivatives;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
MockLayoutBlockDeriver::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
MockLayoutBlockDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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.

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