You are here

class CustomMetaDeriverProperty in Custom Meta 2.0.x

Create a new custom_meta tag plugin for property custom tags.

Hierarchy

Expanded class hierarchy of CustomMetaDeriverProperty

File

src/Plugin/Derivative/CustomMetaDeriverProperty.php, line 10

Namespace

Drupal\custom_meta\Plugin\Derivative
View source
class CustomMetaDeriverProperty extends DeriverBase {

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // Get a list of all custom defined metas.
    $custom_meta_settings = \Drupal::config('custom_meta.settings');
    $custom_meta = $custom_meta_settings
      ->get('tag');
    $custom_meta_prefix = $custom_meta_settings
      ->get('prefix');

    // Now we loop over them and declare the derivatives.
    foreach ($custom_meta as $id => $meta) {
      if ($meta['attribute'] == 'property') {

        // The base definition includes the annotations defined in the plugin,
        // i.e. CustomMetaTagProperty. Each one may be overridden.
        $derivative = $base_plugin_definition;

        // Here we fill in any missing keys on the layout annotation.
        $derivative['weight']++;
        $derivative['id'] = $id;
        $derivative['name'] = $custom_meta_prefix . $id;
        $derivative['label'] = t($meta['label']);
        $derivative['description'] = t($meta['description']);

        // Reference derivatives based on their UUID instead of the record ID.
        $this->derivatives[$derivative['id']] = $derivative;
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomMetaDeriverProperty::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition