コード例 #1
0
 /**
  * Tests the get() method with a configurable plugin.
  */
 public function testGetWithConfigurablePlugin()
 {
     $plugin = $this->getMock('Drupal\\search\\Plugin\\ConfigurableSearchPluginInterface');
     $plugin->expects($this->once())->method('setSearchPageId')->with('fruit_stand')->will($this->returnValue($plugin));
     $this->pluginManager->expects($this->once())->method('createInstance')->will($this->returnValue($plugin));
     $this->assertSame($plugin, $this->searchPluginBag->get('banana'));
 }
コード例 #2
0
    /**
     * {@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);
    }
コード例 #3
0
 /**
  * {@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);
 }
コード例 #4
0
 /**
  * {@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();
 }
コード例 #5
0
 /**
  * {@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;
 }
コード例 #6
0
 /**
  * {@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);
 }
コード例 #7
0
ファイル: EditorManagerTest.php プロジェクト: ddrozdik/dmaps
 /**
  * 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.');
 }
コード例 #8
0
 /**
  * {@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
0
 /**
  * {@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));
 }
コード例 #10
0
 /**
  * Additional #pre_render callback for 'text_format' elements.
  */
 function preRenderTextFormat(array $element)
 {
     // Allow modules to programmatically enforce no client-side editor by
     // setting the #editor property to FALSE.
     if (isset($element['#editor']) && !$element['#editor']) {
         return $element;
     }
     // filter_process_format() copies properties to the expanded 'value' child
     // element, including the #pre_render property. Skip this text format
     // widget, if it contains no 'format'.
     if (!isset($element['format'])) {
         return $element;
     }
     $format_ids = array_keys($element['format']['format']['#options']);
     // Early-return if no text editor is associated with any of the text formats.
     $editors = Editor::loadMultiple($format_ids);
     if (count($editors) === 0) {
         return $element;
     }
     // Use a hidden element for a single text format.
     $field_id = $element['value']['#id'];
     if (!$element['format']['format']['#access']) {
         // Use the first (and only) available text format.
         $format_id = $format_ids[0];
         $element['format']['editor'] = array('#type' => 'hidden', '#name' => $element['format']['format']['#name'], '#value' => $format_id, '#attributes' => array('class' => array('editor'), 'data-editor-for' => $field_id));
     } else {
         $element['format']['format']['#attributes']['class'][] = 'editor';
         $element['format']['format']['#attributes']['data-editor-for'] = $field_id;
     }
     // Hide the text format's filters' guidelines of those text formats that have
     // a text editor associated: they're rather useless when using a text editor.
     foreach ($editors as $format_id => $editor) {
         $element['format']['guidelines'][$format_id]['#access'] = FALSE;
     }
     // Attach Text Editor module's (this module) library.
     $element['#attached']['library'][] = 'editor/drupal.editor';
     // Attach attachments for all available editors.
     $element['#attached'] = drupal_merge_attached($element['#attached'], $this->pluginManager->getAttachments($format_ids));
     // Apply XSS filters when editing content if necessary. Some types of text
     // editors cannot guarantee that the end user won't become a victim of XSS.
     if (!empty($element['value']['#value'])) {
         $original = $element['value']['#value'];
         $format = FilterFormat::load($element['format']['format']['#value']);
         // Ensure XSS-safety for the current text format/editor.
         $filtered = editor_filter_xss($original, $format);
         if ($filtered !== FALSE) {
             $element['value']['#value'] = $filtered;
         }
         // Only when the user has access to multiple text formats, we must add data-
         // attributes for the original value and change tracking, because they are
         // only necessary when the end user can switch between text formats/editors.
         if ($element['format']['format']['#access']) {
             $element['value']['#attributes']['data-editor-value-is-changed'] = 'false';
             $element['value']['#attributes']['data-editor-value-original'] = $original;
         }
     }
     return $element;
 }
コード例 #11
0
ファイル: FieldType.php プロジェクト: sgtsaughter/d8portfolio
 /**
  * {@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);
     }
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
ファイル: KeyForm.php プロジェクト: rlhawk/key
 /**
  * {@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);
 }
コード例 #14
0
 /**
  * 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']));
 }
コード例 #15
0
 /**
  * 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('&nbsp;', array());
     $this->entityParser = $entityParser;
 }
コード例 #16
0
 /**
  * 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;
 }
コード例 #17
0
ファイル: EditorSelector.php プロジェクト: eigentor/tommiblog
 /**
  * {@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);
 }
 /**
  * @covers ::createInstance
  */
 public function testCreateInstance()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_a = $this->getMock(PluginInspectionInterface::class);
     $plugin_id_b = $this->randomMachineName();
     $plugin_b = $this->getMock(PaymentAwarePluginFilteredPluginManagerUnitTestPaymentAwarePlugin::class);
     $plugin_b->expects($this->atLeastOnce())->method('setPayment')->with($this->payment);
     $map = [[$plugin_id_a, [], $plugin_a], [$plugin_id_b, [], $plugin_b]];
     $this->pluginManager->expects($this->atLeast(count($map)))->method('createInstance')->willReturnMap($map);
     $this->assertSame($plugin_a, $this->sut->createInstance($plugin_id_a));
     $this->assertSame($plugin_b, $this->sut->createInstance($plugin_id_b));
 }
コード例 #19
0
 /**
  * Sets up the default plugin collection.
  *
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|null $create_count
  *   (optional) The number of times that createInstance() is expected to be
  *   called. For example, $this->any(), $this->once(), $this->exactly(6).
  *   Defaults to $this->never().
  */
 protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL)
 {
     $this->pluginInstances = array();
     $map = array();
     foreach ($this->getPluginDefinitions() as $plugin_id => $definition) {
         // Create a mock plugin instance.
         $this->pluginInstances[$plugin_id] = $this->getPluginMock($plugin_id, $definition);
         $map[] = array($plugin_id, $this->config[$plugin_id], $this->pluginInstances[$plugin_id]);
     }
     $create_count = $create_count ?: $this->never();
     $this->pluginManager->expects($create_count)->method('createInstance')->will($this->returnCallback(array($this, 'returnPluginMap')));
     $this->defaultPluginCollection = new DefaultLazyPluginCollection($this->pluginManager, $this->config);
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  * @covers ::setDiscoveryLimit
  * @covers ::resetDiscoveryLimit
  */
 public function testGetDefinitionsWithoutAllowedPlugins()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_definition_a = ['id' => $plugin_id_a];
     $plugin_id_b = $this->randomMachineName();
     $plugin_definition_b = ['id' => $plugin_id_b];
     $plugin_id_c = $this->randomMachineName();
     $plugin_definition_c = ['id' => $plugin_id_c];
     $plugin_definitions = [$plugin_id_a => $plugin_definition_a, $plugin_id_b => $plugin_definition_b, $plugin_id_c => $plugin_definition_c];
     $this->pluginManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions);
     $this->sut->setDiscoveryLimit([]);
     $this->assertEquals([], $this->sut->getDefinitions());
 }
コード例 #21
0
 /**
  * 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;
         }
     }
 }
コード例 #22
0
 /**
  * @covers ::getPermissions
  */
 public function testInvoke()
 {
     $payment_method_configuration_plugin_id = $this->randomMachineName();
     $payment_method_configuration_label = $this->randomMachineName();
     $payment_method_configuration_definitions = array($payment_method_configuration_plugin_id => array('label' => $payment_method_configuration_label));
     $this->paymentMethodConfigurationManager->expects($this->once())->method('getDefinitions')->willReturn($payment_method_configuration_definitions);
     $permissions = $this->sut->getPermissions();
     $this->assertInternalType('array', $permissions);
     foreach ($permissions as $permission) {
         $this->assertInternalType('array', $permission);
         $this->assertArrayHasKey('title', $permission);
     }
     $this->arrayHasKey('payment.payment_method_configuration.create.' . $payment_method_configuration_plugin_id, $permissions);
 }
コード例 #23
0
ファイル: KeyForm.php プロジェクト: nerdstein/key
 /**
  * {@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);
 }
コード例 #24
0
 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);
     }
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  */
 public function testGetDefinitions()
 {
     $decorated_plugin_id_a = $this->randomMachineName();
     $decorated_plugin_definition_a = ['id' => $decorated_plugin_id_a];
     $decorated_plugin_id_b = $this->randomMachineName();
     $decorated_plugin_definition_b = ['id' => $decorated_plugin_id_b];
     $decorated_plugin_definitions = [$decorated_plugin_id_a => $decorated_plugin_definition_a, $decorated_plugin_id_b => $decorated_plugin_definition_b];
     $this->pluginManager->expects($this->once())->method('getDefinitions')->willReturn($decorated_plugin_definitions);
     $typed_plugin_definition_a = $this->getMock(PluginDefinitionInterface::class);
     $typed_plugin_definition_b = $this->getMock(PluginDefinitionInterface::class);
     $map = [[$decorated_plugin_definition_a, $typed_plugin_definition_a], [$decorated_plugin_definition_b, $typed_plugin_definition_b]];
     $this->pluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnMap($map);
     $expected_plugin_definitions = [$decorated_plugin_id_a => $typed_plugin_definition_a, $decorated_plugin_id_b => $typed_plugin_definition_b];
     $this->assertSame($expected_plugin_definitions, $this->sut->getDefinitions());
 }
コード例 #26
0
 /**
  * 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;
 }
コード例 #27
0
 /**
  * {@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);
 }
コード例 #28
0
ファイル: Services.php プロジェクト: Jbartsch/travelbruh-api
 /**
  * Processing the API request.
  */
 public function processRequest(Request $request, RouteMatchInterface $route_match, $service_endpoint_id, $service_definition_id)
 {
     /** @var $service_endpoint \Drupal\services\ServiceEndpointInterface */
     $service_endpoint = $this->entityManager()->getStorage('service_endpoint')->load($service_endpoint_id);
     //TODO - pull in settings from service API and alter response
     /** @var $service_def \Drupal\services\ServiceDefinitionInterface */
     $service_def = $this->serviceDefinitionManager->createInstance($service_definition_id, []);
     /**
      * Iterate over any contexts defined for this plugin and extract them from
      * the request defaults if the naming is identical. This means that a
      * context named 'node' would match to a url parameter {node} or a route
      * default named 'node'.
      */
     foreach ($service_def->getContextDefinitions() as $context_id => $context_definition) {
         if ($request->attributes->has($context_id)) {
             $context = new Context($context_definition, $request->attributes->get($context_id));
             $service_def->setContext($context_id, $context);
         }
     }
     // Get the data from the plugin.
     $data = $service_def->processRequest($request, $route_match, $this->serializer);
     $code = $service_def->getPluginDefinition()['response_code'];
     $headers = [];
     $messages = drupal_get_messages();
     if ($messages) {
         foreach ($messages as $type => $type_message) {
             $headers["X-Drupal-Services-Messages-{$type}"] = implode("; ", $type_message);
         }
     }
     // Find the request format to determin how we're going to serialize this data
     $format = $request->getRequestFormat();
     $data = $this->serializer->serialize($data, $format);
     /**
      * Create a new Cacheable Response object with our serialized data, set its
      * Content-Type to match the format of our Request and add the service
      * definition plugin as a cacheable dependency.
      *
      * This last step will extract the cache context, tags and max-ages from
      * any context the plugin required to operate.
      */
     $response = new CacheableResponse($data, $code, $headers);
     $response->headers->add(['Content-Type' => $request->getMimeType($format)]);
     $response->addCacheableDependency($service_def);
     // Be explicit about the caching needs of this response.
     $response->setVary('Accept');
     $service_def->processResponse($response);
     return $response;
 }
コード例 #29
0
 /**
  * Builds the Drupal 8 router by running the Drupal 7 router items through
  * the appropriate route converters.
  *
  * @return RouterInterface
  */
 private function buildDestinationRoutes()
 {
     // @todo These are currently hardcoded on the D7 -> D8 conversion. Make this
     //   configurable.
     $router = new Drupal8Router();
     $this->routeMap = [];
     foreach ($this->getSourceRoutes() as $path => $route) {
         /** @var Drupal7\RouteWrapper $route */
         // If the route hasn't got a page callback...don't even try.
         if (!$route->containsKey('page callback')) {
             continue;
         }
         // Get the appropriate route converter, which will build the route
         // definition.
         $plugin_id = $route['page callback'];
         if (!$this->routeConverters->hasDefinition($plugin_id)) {
             $plugin_id = 'default';
         }
         /** @var Drupal8\RouteWrapper $d8_route */
         $d8_route = $this->routeConverters->createInstance($plugin_id)->buildRouteDefinition($this->target, $route);
         $router->addRoute($d8_route);
         $this->routeMap[$path] = $d8_route->getIdentifier();
     }
     $router->finalize();
     foreach ($this->getSourceRoutes()->getDefaultLocalTasks() as $path => $route) {
         /** @var Drupal7\RouteWrapper $route */
         if ($route->hasParent()) {
             $parent = (string) $route->getParent()->getPath();
             $this->routeMap[$path] = $this->routeMap[$parent];
         }
     }
     return $router;
 }
コード例 #30
0
 /**
  * @covers ::getVariant
  *
  * @depends testAddVariant
  */
 public function testGetVariant($data)
 {
     list($trait_object, $uuid, $plugin) = $data;
     $this->manager->createInstance()->shouldNotBeCalled();
     $this->assertSame($plugin, $trait_object->getVariant($uuid));
     return [$trait_object, $uuid];
 }