本文整理汇总了PHP中Drupal\Component\Plugin\PluginManagerInterface::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP PluginManagerInterface::createInstance方法的具体用法?PHP PluginManagerInterface::createInstance怎么用?PHP PluginManagerInterface::createInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Plugin\PluginManagerInterface
的用法示例。
在下文中一共展示了PluginManagerInterface::createInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* {@inheritdoc}
*/
public function convert(TargetInterface $target)
{
// If the hook implementation contains logic, we cannot convert it and
// that's that. So we'll leave a FIXME and bail out.
/** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
$hook = $target->getIndexer('function')->get('hook_menu');
if ($hook->is(new ContainsLogicFilter())) {
$hook->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
$target->save($hook);
return;
}
$hook_menu = new HookMenu($target, $this->routeConverters);
foreach ($hook_menu->getSourceRoutes() as $path => $route) {
/** @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper $route */
if ($route->containsKey('page callback')) {
$plugin_id = $this->routeConverters->hasDefinition($route['page callback']) ? $route['page callback'] : 'default';
/** @var \Drupal\drupalmoduleupgrader\Routing\RouteConverterInterface $converter */
$this->routeConverters->createInstance($plugin_id)->buildRoute($target, $route);
}
}
$routing = [];
foreach ($hook_menu->getDestinationRoutes() as $name => $route) {
$routing[$name] = ['path' => $route->getPath()->__toString(), 'defaults' => $route->getDefaults(), 'requirements' => $route->getRequirements()];
}
$this->writeInfo($target, 'routing', $routing);
}
示例2: getProcess
/**
* {@inheritdoc}
*/
public function getProcess()
{
if (!$this->init) {
$this->init = TRUE;
$source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin();
if ($source_plugin instanceof RequirementsInterface) {
try {
$source_plugin->checkRequirements();
} catch (RequirementsException $e) {
// Kill the rest of the method.
$source_plugin = [];
}
}
foreach ($source_plugin as $row) {
$field_type = $row->getSourceProperty('type');
if (!isset($this->processedFieldTypes[$field_type]) && $this->cckPluginManager->hasDefinition($field_type)) {
$this->processedFieldTypes[$field_type] = TRUE;
// Allow the cckfield plugin to alter the migration as necessary so
// that it knows how to handle fields of this type.
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
}
call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this);
}
}
}
return parent::getProcess();
}
示例3: convert
/**
* {@inheritdoc}
*/
public function convert(TargetInterface $target)
{
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $target->getIndexer('function')->get('hook_user_login');
// The $edit parameter is defunct in Drupal 8, but we'll leave it in
// there as an empty array to prevent errors, and move it to the back
// of the line.
/** @var \Pharborist\Functions\ParameterNode $edit */
$edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(ArrayNode::create([]));
$function->appendParameter($edit);
// Slap a FIXME on the hook implementation, informing the developer that
// $edit and $category are dead.
$comment = $function->getDocComment();
$comment_text = $comment ? $comment->getCommentText() : '';
if ($comment_text) {
$comment_text .= "\n\n";
}
$comment_text .= <<<'END'
@FIXME
The $edit parameter is gone in Drupal 8. It has been left here in order to
prevent 'undefined variable' errors, but it will never actually be passed to
this hook. You'll need to modify this function and remove every reference to it.
END;
$function->setDocComment(DocCommentNode::create($comment_text));
$rewriter = $this->rewriters->createInstance('_rewriter:user');
$this->rewriteFunction($rewriter, $function->getParameterAtIndex(0), $target);
$target->save($function);
}
示例4: initializePlugin
/**
* {@inheritdoc}
*/
protected function initializePlugin($plugin_id)
{
if (isset($this->pluginInstances[$plugin_id])) {
return;
}
$this->pluginInstances[$plugin_id] = $this->manager->createInstance($plugin_id, array(), $this->style);
}
示例5: testManager
/**
* Tests the configurable text editor manager.
*/
public function testManager()
{
$this->editorManager = $this->container->get('plugin.manager.editor');
// Case 1: no text editor available:
// - listOptions() should return an empty list of options
// - getAttachments() should return an empty #attachments array (and not
// a JS settings structure that is empty)
$this->assertIdentical(array(), $this->editorManager->listOptions(), 'When no text editor is enabled, the manager works correctly.');
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when no text editor is enabled and retrieving attachments for zero text formats.');
$this->assertIdentical(array(), $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'No attachments when no text editor is enabled and retrieving attachments for multiple text formats.');
// Enable the Text Editor Test module, which has the Unicorn Editor and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('editor_test'));
$this->editorManager = $this->container->get('plugin.manager.editor');
$this->editorManager->clearCachedDefinitions();
// Case 2: a text editor available.
$this->assertIdentical('Unicorn Editor', (string) $this->editorManager->listOptions()['unicorn'], 'When some text editor is enabled, the manager works correctly.');
// Case 3: a text editor available & associated (but associated only with
// the 'Full HTML' text format).
$unicorn_plugin = $this->editorManager->createInstance('unicorn');
$editor = entity_create('editor', array('format' => 'full_html', 'editor' => 'unicorn'));
$editor->save();
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when one text editor is enabled and retrieving attachments for zero text formats.');
$expected = array('library' => array(0 => 'editor_test/unicorn'), 'drupalSettings' => ['editor' => ['formats' => ['full_html' => ['format' => 'full_html', 'editor' => 'unicorn', 'editorSettings' => $unicorn_plugin->getJSSettings($editor), 'editorSupportsContentFiltering' => TRUE, 'isXssSafe' => FALSE]]]]);
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');
// Case 4: a text editor available associated, but now with its JS settings
// being altered via hook_editor_js_settings_alter().
\Drupal::state()->set('editor_test_js_settings_alter_enabled', TRUE);
$expected['drupalSettings']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'hook_editor_js_settings_alter() works correctly.');
}
示例6: generateFieldMetadata
/**
* {@inheritdoc}
*/
public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
{
$entity = $items->getEntity();
$field_name = $items->getFieldDefinition()->getName();
// Early-return if user does not have access.
$access = $this->accessChecker->accessEditEntityField($entity, $field_name);
if (!$access) {
return array('access' => FALSE);
}
// Early-return if no editor is available.
$formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
$editor_id = $this->editorSelector->getEditor($formatter_id, $items);
if (!isset($editor_id)) {
return array('access' => FALSE);
}
// Gather metadata, allow the editor to add additional metadata of its own.
$label = $items->getFieldDefinition()->getLabel();
$editor = $this->editorManager->createInstance($editor_id);
$metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)));
$custom_metadata = $editor->getMetadata($items);
if (count($custom_metadata)) {
$metadata['custom'] = $custom_metadata;
}
return $metadata;
}
示例7: initializePlugin
/**
* {@inheritdoc}
*/
protected function initializePlugin($instance_id)
{
$configuration = isset($this->configurations[$instance_id]) ? $this->configurations[$instance_id] : array();
if (!isset($configuration[$this->pluginKey])) {
throw new PluginNotFoundException($instance_id);
}
$this->set($instance_id, $this->manager->createInstance($configuration[$this->pluginKey], $configuration));
}
示例8: createInstance
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = [])
{
if ($this->hasDefinition($plugin_id)) {
return $this->decoratedFactory->createInstance($plugin_id, $configuration);
} else {
throw new PluginNotFoundException($plugin_id);
}
}
示例9: transform
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
$field_type = is_array($value) ? $value[0] : $value;
try {
return $this->cckPluginManager->createInstance($field_type, [], $this->migration)->getFieldType($row);
} catch (PluginNotFoundException $e) {
return parent::transform($value, $migrate_executable, $row, $destination_property);
}
}
示例10: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
// Only run key provider settings validation if the form is being submitted
if ($form_state->isSubmitted()) {
$plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []);
$plugin->validateConfigurationForm($form, $form_state);
}
parent::validateForm($form, $form_state);
}
示例11: testFormatTagsSettings
/**
* Test the format tags settings.
*
* @dataProvider formatTagsSettingsTestCases
*/
public function testFormatTagsSettings($filter_plugins, $expected_format_tags)
{
foreach ($filter_plugins as $filter_plugin_id => $filter_plugin_settings) {
$this->format->setFilterConfig($filter_plugin_id, $filter_plugin_settings);
}
$this->format->save();
$internal_plugin = $this->ckeditorPluginManager->createInstance('internal', []);
$plugin_config = $internal_plugin->getConfig($this->editor);
$this->assertEquals($expected_format_tags, explode(';', $plugin_config['format_tags']));
}
示例12: getEditorAttachments
/**
* {@inheritdoc}
*/
public function getEditorAttachments(array $editor_ids)
{
$attachments = array();
$editor_ids = array_unique($editor_ids);
// Editor plugins' attachments.
foreach ($editor_ids as $editor_id) {
$editor = $this->editorManager->createInstance($editor_id);
$attachments[] = $editor->getAttachments();
}
return NestedArray::mergeDeepArray($attachments);
}
示例13: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
// Only run key settings validation if the form is being submitted
if ($form_state->isSubmitted()) {
$plugin_settings = (new FormState())->setValues($form_state->getValue('key_settings'));
$plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []);
$plugin->validateConfigurationForm($form, $plugin_settings);
// Reinject errors from $plugin_settings into $form_state
foreach ($plugin_settings->getErrors() as $field => $error) {
$form_state->setErrorByName($field, $error);
}
}
parent::validateForm($form, $form_state);
}
示例14: convert
public function convert(TargetInterface $target)
{
$indexer = $target->getIndexer('function');
$hooks = array_filter($this->pluginDefinition['hook'], [$indexer, 'has']);
foreach ($hooks as $hook) {
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $indexer->get($hook);
$function->prependParameter(ParameterNode::create('build')->setTypeHint('array')->setReference(TRUE));
// Extract the entity type from the hook name (e.g. 'hook_node_view').
preg_match('/^hook_(.+)_view$/', $hook, $matches);
$entity_type = $matches[1];
$rewriter = $this->rewriters->createInstance('_rewriter:' . $entity_type);
$this->rewriteFunction($rewriter, $function->getParameterAtIndex(1), $target);
}
}
示例15: convert
/**
* {@inheritdoc}
*/
public function convert(TargetInterface $target)
{
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $target->getIndexer('function')->get('hook_node_prepare');
// foo_node_prepare() --> foo_node_prepare_form().
$function->setName($function->getName() . '_form');
// The first parameter is a node, so rewrite the function accordingly.
$this->rewriters->createInstance('_entity:node')->rewrite($function->getParameterAtIndex(0));
// Create the $operation parameter.
$function->appendParameter(ParameterNode::create('operation'));
// Create the $form_state parameter.
$form_state = ParameterNode::create('form_state')->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
$function->appendParameter($form_state);
$target->save($function);
}