/** * Constructs a FullcalendarPluginBag object. * * @param \Drupal\Component\Plugin\PluginManagerInterface $manager * The manager to be used for instantiating plugins. * @param \Drupal\views\Plugin\views\style\StylePluginBase $style * The style plugin that contains these plugins. */ public function __construct(PluginManagerInterface $manager, StylePluginBase $style) { $this->manager = $manager; $this->style = $style; // Store all display IDs to access them easy and fast. $definitions = $this->manager->getDefinitions(); $this->instanceIDs = drupal_map_assoc(array_keys($definitions)); }
/** * Returns permissions. * * @return array[] * The structure is the same as that of *.permissions.yml files. */ public function getPermissions() { $permissions = []; $definitions = $this->paymentMethodConfigurationManager->getDefinitions(); foreach ($definitions as $plugin_id => $definition) { $permissions['payment.payment_method_configuration.create.' . $plugin_id] = array('title' => $this->t('Create %plugin_label payment method configurations', array('%plugin_label' => $definition['label']))); } return $permissions; }
/** * Loads the plugin configuration. * * @return bool[] * Keys are currency_exchanger plugin names. Values are booleans that * describe whether the plugins are enabled. Items are ordered by weight. */ public function loadConfiguration() { $definitions = $this->currencyExchangeRateProviderManager->getDefinitions(); $configuration_data = $this->configFactory->get('currency.exchange_rate_provider')->get('plugins'); $configuration = array(); foreach ($configuration_data as $data) { $configuration[$data['plugin_id']] = $data['status']; } return $configuration + array_fill_keys(array_keys($definitions), FALSE); }
/** * Invokes the implementation. */ public function invoke() { $bundles = []; foreach ($this->paymentTypeManager->getDefinitions() as $plugin_id => $definition) { $bundles['payment'][$plugin_id] = array('label' => $definition['label']); } foreach ($this->paymentMethodConfigurationManager->getDefinitions() as $plugin_id => $definition) { $bundles['payment_method_configuration'][$plugin_id] = array('label' => $definition['label']); } return $bundles; }
/** * Gets the parent task's link ID, if any. * * @return string|NULL */ public function getParentID() { $path = $this->getSource()->getParent()->getPath()->__toString(); if ($this->index->containsKey($path)) { return $this->index[$path]->getIdentifier(); } $parent = $this->getDestination()->getParent()->getIdentifier(); foreach ($this->linkManager->getDefinitions() as $id => $link) { if ($link['route_name'] == $parent) { return $id; } } }
/** * Create template list table. * * @return array * Render array of template list. */ public function templateList() { $table = array('#type' => 'table', '#header' => array($this->t('Name'), $this->t('Description'), $this->t('Add')), '#empty' => $this->t('There are no available Views Templates')); /** @var \Drupal\views_templates\Plugin\ViewsBuilderPluginInterface $definition */ foreach ($this->builder_manager->getDefinitions() as $definition) { /** @var \Drupal\views_templates\Plugin\ViewsBuilderPluginInterface $builder */ $builder = $this->builder_manager->createInstance($definition['id']); if ($builder->templateExists()) { $plugin_id = $builder->getPluginId(); $row = ['name' => ['#plain_text' => $builder->getAdminLabel()], 'description' => ['#plain_text' => $builder->getDescription()], 'add' => ['#type' => 'link', '#title' => t('Add'), '#url' => Url::fromRoute('views_templates.create_from_template', ['view_template' => $plugin_id])]]; $table[$plugin_id] = $row; } } return $table; }
/** * Destroys all index data for this target. */ public function destroyIndex() { $indexers = array_keys($this->indexerManager->getDefinitions()); foreach ($indexers as $id) { $this->getIndexer($id)->destroy(); } }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // The table containing all the field types discovered in the system. $form['fields'] = array('#type' => 'table', '#tree' => TRUE, '#header' => $this->getTableHeader(), '#empty' => $this->t('No field types found.'), '#prefix' => '<div id="field-display-overview-wrapper">', '#suffix' => '</div>', '#attributes' => array('class' => array('field-ui-overview'), 'id' => 'field-display-overview')); // Get the definition of all @FieldDiffBuilder plugins. $diff_plugin_definitions = $this->diffBuilderManager->getDefinitions(); $plugins = array(); foreach ($diff_plugin_definitions as $plugin_definition) { if (isset($plugin_definition['field_types'])) { // Iterate through all the field types this plugin supports // and for every such field type add the id of the plugin. foreach ($plugin_definition['field_types'] as $id) { $plugins[$id][] = $plugin_definition['id']; } } } // Get all the field type plugins. $field_definitions = $this->fieldTypePluginManager->getDefinitions(); foreach ($field_definitions as $field_type => $field_definition) { // Build a row in the table for every field type. $form['fields'][$field_type] = $this->buildFieldRow($field_type, $field_definition, $plugins, $diff_plugin_definitions, $form_state); } // Submit button for the form. $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Save')); $form['#attached']['library'][] = 'field_ui/drupal.field_ui'; $form['#attached']['library'][] = 'diff/diff.general'; return $form; }
/** * Presents a list of display variants to add to the page entity. * * @param \Drupal\page_manager\PageInterface $page * The page entity. * * @return array * The display variant selection page. */ public function selectDisplayVariant(PageInterface $page) { $build = ['#theme' => 'links', '#links' => []]; foreach ($this->variantManager->getDefinitions() as $display_variant_id => $display_variant) { $build['#links'][$display_variant_id] = ['title' => $display_variant['admin_label'], 'url' => Url::fromRoute('page_manager.display_variant_add', ['page' => $page->id(), 'display_variant_id' => $display_variant_id]), 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])]]; } return $build; }
/** * Presents a list of variants to add to the page entity. * * @param \Drupal\page_manager\PageInterface $page * The page entity. * * @return array * The variant selection page. */ public function selectVariant(PageInterface $page) { $build = ['#theme' => 'links', '#links' => []]; foreach ($this->variantManager->getDefinitions() as $variant_plugin_id => $variant_plugin) { $build['#links'][$variant_plugin_id] = ['title' => $variant_plugin['admin_label'], 'url' => Url::fromRoute('entity.page_variant.add_form', ['page' => $page->id(), 'variant_plugin_id' => $variant_plugin_id]), 'attributes' => $this->getAjaxAttributes()]; } return $build; }
/** * {@inheritdoc} */ public function getNegotiationMethods($type = NULL) { $definitions = $this->negotiatorManager->getDefinitions(); if (isset($type)) { $enabled_methods = $this->getEnabledNegotiators($type); $definitions = array_intersect_key($definitions, $enabled_methods); } return $definitions; }
/** * Constructs an EntityComparisonBase object. * * @param DiffFormatter $diff_formatter * Diff formatter service. * @param DateFormatter $date * DateFormatter service. * @param PluginManagerInterface $plugin_manager * The Plugin manager service. * @param DiffEntityParser $entityParser * The diff field builder plugin manager. */ public function __construct(DiffFormatter $diff_formatter, DateFormatter $date, PluginManagerInterface $plugin_manager, DiffEntityParser $entityParser) { $this->diffFormatter = $diff_formatter; $this->date = $date; $this->fieldTypeDefinitions = $plugin_manager->getDefinitions(); $this->config = $this->config('diff.settings'); $this->pluginsConfig = $this->config('diff.plugins'); $this->nonBreakingSpace = new FormattableMarkup(' ', array()); $this->entityParser = $entityParser; }
/** * {@inheritdoc} */ public function getEditor($formatter_type, FieldItemListInterface $items) { // Build a static cache of the editors that have registered themselves as // alternatives to a certain editor. if (!isset($this->alternatives)) { $editors = $this->editorManager->getDefinitions(); foreach ($editors as $alternative_editor_id => $editor) { if (isset($editor['alternativeTo'])) { foreach ($editor['alternativeTo'] as $original_editor_id) { $this->alternatives[$original_editor_id][] = $alternative_editor_id; } } } } // Check if the formatter defines an appropriate in-place editor. For // example, text formatters displaying untrimmed text can choose to use the // 'plain_text' editor. If the formatter doesn't specify, fall back to the // 'form' editor, since that can work for any field. Formatter definitions // can use 'disabled' to explicitly opt out of in-place editing. $formatter_info = $this->formatterManager->getDefinition($formatter_type); $editor_id = $formatter_info['quickedit']['editor']; if ($editor_id === 'disabled') { return; } elseif ($editor_id === 'form') { return 'form'; } // No early return, so create a list of all choices. $editor_choices = array($editor_id); if (isset($this->alternatives[$editor_id])) { $editor_choices = array_merge($editor_choices, $this->alternatives[$editor_id]); } // Make a choice. foreach ($editor_choices as $editor_id) { $editor = $this->editorManager->createInstance($editor_id); if ($editor->isCompatible($items)) { return $editor_id; } } // We still don't have a choice, so fall back to the default 'form' editor. return 'form'; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); /** @var $service_endpoint \Drupal\services\Entity\ServiceEndpoint */ $service_endpoint = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $service_endpoint->label(), '#description' => $this->t("Label for the service endpoint."), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $service_endpoint->id(), '#machine_name' => array('exists' => '\\Drupal\\services\\Entity\\ServiceEndpoint::load'), '#disabled' => !$service_endpoint->isNew()); $form['endpoint'] = array('#type' => 'textfield', '#title' => $this->t('Endpoint'), '#maxlength' => 255, '#default_value' => $service_endpoint->getEndpoint(), '#description' => $this->t("URL endpoint."), '#required' => TRUE); $opts = []; foreach ($this->manager->getDefinitions() as $plugin_id => $definition) { $opts[$plugin_id] = ['title' => (string) $definition['title'], 'endpoint' => $definition['path'], 'category' => $definition['category']]; if (isset($definition['warning'])) { $opts[$plugin_id]['description'] = $definition['warning'] . ' ' . $definition['description']; $opts[$plugin_id]['#attributes'] = array('class' => array('services-experimental')); } else { $opts[$plugin_id]['description'] = $definition['description']; } } $form['service_providers'] = array('#type' => 'tableselect', '#header' => ['title' => $this->t('Definition'), 'endpoint' => $this->t('Endpoint'), 'category' => $this->t('Category'), 'description' => $this->t('Description')], '#title' => $this->t('Service Provider'), '#empty' => t('No service definitions exist'), '#required' => TRUE, '#options' => $opts, '#default_value' => $service_endpoint->getServiceProviders(), '#attached' => array('library' => array('services/services.admin'))); return $form; }
/** * {@inheritdoc} */ public function getContainerDefinition() { $definitions = $this->serviceProviderManager->getDefinitions(); $container_definition = array(); $service_providers = array(); // Populate service providers. foreach ($definitions as $plugin_id => $definition) { $service_providers[$plugin_id] = $this->serviceProviderManager->createInstance($plugin_id); } // Get container definition of each service provider and merge them. foreach ($definitions as $plugin_id => $definition) { $service_provider = $service_providers[$plugin_id]; $container_definition = NestedArray::mergeDeep($container_definition, $service_provider->getContainerDefinition()); } $container_definition += array('services' => array(), 'parameters' => array()); // @codeCoverageIgnore // Find and setup tags for container altering. $container_definition['tags'] = array(); // Setup the tags structure. foreach ($container_definition['services'] as $service => $definition) { if (isset($definition['tags'])) { foreach ($definition['tags'] as $tag) { $tag_name = $tag['name']; unset($tag['name']); $container_definition['tags'][$tag_name][$service][] = $tag; } } } // Ensure container definition can be altered. foreach ($definitions as $plugin_id => $definition) { $service_provider = $service_providers[$plugin_id]; $service_provider->alterContainerDefinition($container_definition); } // Last give a chance for traditional modules to alter this. $this->moduleAlter($container_definition); // Remove the tags again, not needed for the final build of the container. unset($container_definition['tags']); return $container_definition; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $form['#attached']['library'][] = 'core/drupal.dialog.ajax'; $key_providers = []; foreach ($this->manager->getDefinitions() as $plugin_id => $definition) { $key_providers[$plugin_id] = (string) $definition['title']; } /** @var $key \Drupal\key\KeyInterface */ $key = $this->entity; $form['#tree'] = TRUE; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Key name'), '#maxlength' => 255, '#default_value' => $key->label(), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $key->id(), '#machine_name' => array('exists' => '\\Drupal\\key\\Entity\\Key::load'), '#disabled' => !$key->isNew()); $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $key->getDescription(), '#description' => $this->t('A short description of the key.')); $form['key_provider'] = array('#type' => 'select', '#title' => $this->t('Key Provider'), '#options' => $key_providers, '#empty_option' => t('- Select key provider -'), '#empty_value' => '', '#ajax' => ['callback' => [$this, 'getKeyProviderForm'], 'event' => 'change', 'wrapper' => 'key-provider-form'], '#required' => TRUE, '#default_value' => $key->getKeyProvider()); $form['key_provider_settings'] = ['#prefix' => '<div id="key-provider-form">', '#suffix' => '</div>']; if ($this->manager->hasDefinition($key->getKeyProvider())) { // @todo compare ids to ensure appropriate plugin values. $plugin = $this->manager->createInstance($key->getKeyProvider(), $key->getKeyProviderSettings()); $form['key_provider_settings'] += $plugin->buildConfigurationForm([], $form_state); } return $form; }
/** * Presents a list of variants to add to the page entity. * * @param \Drupal\page_manager\PageInterface $page * The page entity. * * @return array * The variant selection page. */ public function selectVariant(PageInterface $page) { $build = ['#theme' => 'links', '#links' => []]; foreach ($this->variantManager->getDefinitions() as $variant_plugin_id => $variant_plugin) { // The following two variants are provided by Drupal Core. They are not // configurable and therefore not compatible with Page Manager but have // similar and confusing labels. Skip them so that they are not shown in // the UI. if (in_array($variant_plugin_id, ['simple_page', 'block_page'])) { continue; } $build['#links'][$variant_plugin_id] = ['title' => $variant_plugin['admin_label'], 'url' => Url::fromRoute('entity.page_variant.add_form', ['page' => $page->id(), 'variant_plugin_id' => $variant_plugin_id]), 'attributes' => $this->getAjaxAttributes()]; } return $build; }
/** * */ protected function conditionOptions($route_name, $parameters) { $elements = [ '#tree' => TRUE, ]; $this->manager->getDefinitions(); $definitions = $this->manager->getDefinitions(); foreach ($definitions as $id => $info) { /** @var \Drupal\block_visibility_groups_admin\Plugin\ConditionCreatorInterface $creator */ $creator = $this->manager->createInstance( $id, [ 'route_name' => $route_name, 'parameters' => $parameters, ] ); if ($label = $creator->getNewConditionLabel()) { $elements[$id] = $creator->createConditionElements(); } } return $elements; }
/** * {@inheritdoc} */ public function getGenerationMethods() { return $this->generatorManager->getDefinitions(); }
/** * Returns all filter definitions that are provided by the specified provider. * * @param string $provider * The provider of the filters. * * @return array * The filter definitions for the specified provider. */ protected function getFilterDefinitionsByProvider($provider) { return array_filter($this->filterManager->getDefinitions(), function ($definition) use($provider) { return $definition['provider'] == $provider; }); }
/** * {@inheritdoc} */ public function getAssignmentMethods() { return $this->assignerManager->getDefinitions(); }
/** * Tests the enabling of plugins. */ function testEnabledPlugins() { $this->manager = $this->container->get('plugin.manager.ckeditor.plugin'); $editor = Editor::load('filtered_html'); // Case 1: no CKEditor plugins. $definitions = array_keys($this->manager->getDefinitions()); sort($definitions); $this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.'); $enabled_plugins = array('drupalimage' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js', 'drupallink' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupallink/plugin.js'); $this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only built-in plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.'); // Enable the CKEditor Test module, which has the Llama plugin (plus four // variations of it, to cover all possible ways a plugin can be enabled) and // clear the editor manager's cache so it is picked up. $this->enableModules(array('ckeditor_test')); $this->manager = $this->container->get('plugin.manager.ckeditor.plugin'); $this->manager->clearCachedDefinitions(); // Case 2: CKEditor plugins are available. $plugin_ids = array_keys($this->manager->getDefinitions()); sort($plugin_ids); $this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.'); $this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only the internal plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.'); // Case 3: enable each of the newly available plugins, if possible: // a. Llama: cannot be enabled, since it does not implement // CKEditorPluginContextualInterface nor CKEditorPluginButtonsInterface. // b. LlamaContextual: enabled by adding the 'Strike' button, which is // part of another plugin! // c. LlamaButton: automatically enabled by adding its 'Llama' button. // d. LlamaContextualAndButton: enabled by either b or c. // e. LlamaCSS: automatically enabled by add its 'LlamaCSS' button. // Below, we will first enable the "Llama" button, which will cause the // LlamaButton and LlamaContextualAndButton plugins to be enabled. Then we // will remove the "Llama" button and add the "Strike" button, which will // cause the LlamaContextual and LlamaContextualAndButton plugins to be // enabled. Then we will add the "Strike" button back again, which would // cause LlamaButton, LlamaContextual and LlamaContextualAndButton to be // enabled. Finally, we will add the "LlamaCSS" button which would cause // all four plugins to be enabled. $settings = $editor->getSettings(); $original_toolbar = $settings['toolbar']; $settings['toolbar']['rows'][0][0]['items'][] = 'Llama'; $editor->setSettings($settings); $editor->save(); $file = array(); $file['b'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js'; $file['c'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js'; $file['cb'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js'; $file['css'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js'; $expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); $settings['toolbar'] = $original_toolbar; $settings['toolbar']['rows'][0][0]['items'][] = 'Strike'; $editor->setSettings($settings); $editor->save(); $expected = $enabled_plugins + array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $settings['toolbar']['rows'][0][0]['items'][] = 'Llama'; $editor->setSettings($settings); $editor->save(); $expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS'; $editor->setSettings($settings); $editor->save(); $expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.'); }
/** * Constructs a TestLazyPluginCollection object. * * @param \Drupal\Component\Plugin\PluginManagerInterface $manager * The plugin manager that handles test plugins. */ public function __construct(PluginManagerInterface $manager) { $this->manager = $manager; $instance_ids = array_keys($this->manager->getDefinitions()); $this->instanceIDs = array_combine($instance_ids, $instance_ids); }