Пример #1
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);
 }
Пример #2
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();
 }
    /**
     * {@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);
    }
 /**
  * {@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
0
 /**
  * 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.');
 }
 /**
  * {@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;
 }
 /**
  * {@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));
 }
 /**
  * {@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}
  */
 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
0
 /**
  * {@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
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']));
 }
Пример #12
0
 /**
  * {@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
0
 /**
  * {@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);
 }
 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);
     }
 }
 /**
  * {@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);
 }
 /**
  * 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;
 }
Пример #17
0
 /**
  * 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;
 }
Пример #18
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;
 }
 /**
  * Loads or creates a Block Plugin instance suitable for rendering or testing.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return \Drupal\Core\Block\BlockBase
  *   The Block Plugin instance.
  */
 protected function getBlockInstance($form_state)
 {
     /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
     $page_variant = PageVariant::load($form_state->getValue('variant_id'));
     // If a UUID is provided, the Block should already exist.
     if ($uuid = $form_state->getValue('uuid')) {
         /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */
         $variant_plugin = $page_variant->getVariantPlugin();
         // If a temporary configuration for this variant exists, use it.
         $temp_store_key = 'variant.' . $page_variant->id();
         if ($variant_config = $this->tempStore->get($temp_store_key)) {
             $variant_plugin->setConfiguration($variant_config);
         }
         // Load the existing Block instance.
         $block_instance = $variant_plugin->getBlock($uuid);
     } else {
         // Create an instance of this Block plugin.
         /** @var \Drupal\Core\Block\BlockBase $block_instance */
         $block_instance = $this->blockManager->createInstance($form_state->getValue('plugin_id'));
     }
     // Add context to the block.
     if ($block_instance instanceof ContextAwarePluginInterface) {
         $this->contextHandler->applyContextMapping($block_instance, $page_variant->getContexts());
     }
     return $block_instance;
 }
Пример #20
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];
 }
Пример #21
0
 /**
  * Prepares the HTML body: wraps the main content in #type 'page'.
  *
  * @param array $main_content
  *   The render array representing the main content.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object, for context.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match, for context.
  *
  * @return array
  *   An array with two values:
  *   0. A #type 'page' render array.
  *   1. The page title.
  *
  * @throws \LogicException
  *   If the selected display variant does not implement PageVariantInterface.
  */
 protected function prepare(array $main_content, Request $request, RouteMatchInterface $route_match)
 {
     // If the _controller result already is #type => page,
     // we have no work to do: The "main content" already is an entire "page"
     // (see html.html.twig).
     if (isset($main_content['#type']) && $main_content['#type'] === 'page') {
         $page = $main_content;
     } else {
         // Select the page display variant to be used to render this main content,
         // default to the built-in "simple page".
         $event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
         $this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
         $variant_id = $event->getPluginId();
         // We must render the main content now already, because it might provide a
         // title. We set its $is_root_call parameter to FALSE, to ensure
         // placeholders are not yet replaced. This is essentially "pre-rendering"
         // the main content, the "full rendering" will happen in
         // ::renderResponse().
         // @todo Remove this once https://www.drupal.org/node/2359901 lands.
         if (!empty($main_content)) {
             $this->renderer->executeInRenderContext(new RenderContext(), function () use(&$main_content) {
                 if (isset($main_content['#cache']['keys'])) {
                     // Retain #title, otherwise, dynamically generated titles would be
                     // missing for controllers whose entire returned render array is
                     // render cached.
                     $main_content['#cache_properties'][] = '#title';
                 }
                 return $this->renderer->render($main_content, FALSE);
             });
             $main_content = $this->renderCache->getCacheableRenderArray($main_content) + ['#title' => isset($main_content['#title']) ? $main_content['#title'] : NULL];
         }
         // Instantiate the page display, and give it the main content.
         $page_display = $this->displayVariantManager->createInstance($variant_id);
         if (!$page_display instanceof PageVariantInterface) {
             throw new \LogicException('Cannot render the main content for this page because the provided display variant does not implement PageVariantInterface.');
         }
         $page_display->setMainContent($main_content)->setConfiguration($event->getPluginConfiguration());
         // Generate a #type => page render array using the page display variant,
         // the page display will build the content for the various page regions.
         $page = array('#type' => 'page');
         $page += $page_display->build();
     }
     // $page is now fully built. Find all non-empty page regions, and add a
     // theme wrapper function that allows them to be consistently themed.
     $regions = \Drupal::theme()->getActiveTheme()->getRegions();
     foreach ($regions as $region) {
         if (!empty($page[$region])) {
             $page[$region]['#theme_wrappers'][] = 'region';
             $page[$region]['#region'] = $region;
         }
     }
     // Allow hooks to add attachments to $page['#attached'].
     $this->invokePageAttachmentHooks($page);
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
     $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
     return [$page, $title];
 }
 /**
  * {@inheritdoc}
  */
 public function buildRoute(TargetInterface $target, Drupal7Route $route)
 {
     $definition = $this->buildRouteDefinition($target, $route);
     $map = $this->buildParameterMap($target, $route);
     $map->applyRoute($definition->unwrap());
     $indexer = $target->getIndexer('function');
     foreach ($map->toArray() as $function_name => $parameters) {
         if ($parameters && $indexer->has($function_name)) {
             /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
             $function = $indexer->get($function_name);
             foreach ($parameters as $parameter_name => $info) {
                 $parameter = $function->getParameterByName($parameter_name)->setName($info['name'], TRUE);
                 if (isset($info['type'])) {
                     $plugin_id = '_rewriter:' . $info['type'];
                     if ($this->rewriters->hasDefinition($plugin_id)) {
                         $this->rewriters->createInstance($plugin_id)->rewrite($parameter);
                     }
                 }
             }
         }
     }
     $class_indexer = $target->getIndexer('class');
     if ($class_indexer->has('DefaultController')) {
         $controller = $class_indexer->get('DefaultController');
     } else {
         $controller = $this->getController($target, $route);
         $class_indexer->addFile($this->writeClass($target, $controller));
     }
     if ($indexer->has($route['title callback'])) {
         if (!$controller->hasMethod($route['title callback'])) {
             $indexer->get($route['title callback'])->cloneAsMethodOf($controller);
         }
     }
     if ($indexer->has($route['access callback'])) {
         $func = $indexer->get($route['access callback']);
         $returns = $func->find(Filter::isInstanceOf('\\Pharborist\\ReturnStatementNode'));
         foreach ($returns as $ret) {
             $call = ClassMethodCallNode::create('\\Drupal\\Core\\Access\\AccessResult', 'allowedIf')->appendArgument($ret->getExpression());
             $ret->replaceWith(ReturnStatementNode::create($call));
         }
         // The access callback always receives an $account parameter.
         if ($func->hasParameter('account')) {
             $func->getParameter('account')->setTypeHint('Drupal\\Core\\Session\\AccountInterface');
         } else {
             $account = ParameterNode::create('account')->setTypeHint('Drupal\\Core\\Session\\AccountInterface');
             $func->appendParameter($account);
         }
         if (!$controller->hasMethod($route['access callback'])) {
             $func->cloneAsMethodOf($controller);
         }
     }
     if ($indexer->has($route['page callback'])) {
         if (!$controller->hasMethod($route['page callback'])) {
             $indexer->get($route['page callback'])->cloneAsMethodOf($controller);
         }
     }
     $this->writeClass($target, $controller);
 }
 /**
  * Returns an instance of the specified package assignment method.
  *
  * @param string $method_id
  *   The string identifier of the package assignment method to use to package
  *   configuration.
  *
  * @return \Drupal\features\FeaturesAssignmentMethodInterface
  */
 protected function getAssignmentMethodInstance($method_id) {
   if (!isset($this->methods[$method_id])) {
     $instance = $this->assignerManager->createInstance($method_id, array());
     $instance->setFeaturesManager($this->featuresManager);
     $instance->setAssigner($this);
     $this->methods[$method_id] = $instance;
   }
   return $this->methods[$method_id];
 }
 /**
  * {@inheritdoc}
  */
 protected function getExchangeRateProviders()
 {
     $plugin_ids = array_keys(array_filter($this->loadConfiguration()));
     $plugins = array();
     foreach ($plugin_ids as $plugin_id) {
         $plugins[$plugin_id] = $this->currencyExchangeRateProviderManager->createInstance($plugin_id);
     }
     return $plugins;
 }
Пример #25
0
 /**
  * Gets the definition of all derivatives of a base plugin.
  *
  * @param array $base_plugin_definition
  *   The definition array of the base plugin.
  *
  * @return array
  *   An array of full derivative definitions keyed on derivative id.
  *
  * @see \Drupal\Component\Plugin\Derivative\DeriverBase::getDerivativeDefinition()
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     if ($base_plugin_definition['id'] == 'd6_node_translation' && !$this->includeTranslations) {
         // Refuse to generate anything.
         return $this->derivatives;
     }
     // Read all CCK field instance definitions in the source database.
     $fields = array();
     try {
         $source_plugin = static::getSourcePlugin('d6_field_instance');
         $source_plugin->checkRequirements();
         foreach ($source_plugin as $row) {
             $fields[$row->getSourceProperty('type_name')][$row->getSourceProperty('field_name')] = $row->getSource();
         }
     } catch (RequirementsException $e) {
         // If checkRequirements() failed then the content module did not exist and
         // we do not have any CCK fields. Therefore, $fields will be empty and
         // below we'll create a migration just for the node properties.
     }
     try {
         foreach (static::getSourcePlugin('d6_node_type') as $row) {
             $node_type = $row->getSourceProperty('type');
             $values = $base_plugin_definition;
             $values['label'] = t("@label (@type)", ['@label' => $values['label'], '@type' => $node_type]);
             $values['source']['node_type'] = $node_type;
             $values['destination']['default_bundle'] = $node_type;
             // If this migration is based on the d6_node_revision migration or
             // is for translations of nodes, it should explicitly depend on the
             // corresponding d6_node variant.
             if (in_array($base_plugin_definition['id'], ['d6_node_revision', 'd6_node_translation'])) {
                 $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type;
             }
             $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
             if (isset($fields[$node_type])) {
                 foreach ($fields[$node_type] as $field_name => $info) {
                     $field_type = $info['type'];
                     if ($this->cckPluginManager->hasDefinition($info['type'])) {
                         if (!isset($this->cckPluginCache[$field_type])) {
                             $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, ['core' => 6], $migration);
                         }
                         $this->cckPluginCache[$field_type]->processCckFieldValues($migration, $field_name, $info);
                     } else {
                         $migration->setProcessOfProperty($field_name, $field_name);
                     }
                 }
             }
             $this->derivatives[$node_type] = $migration->getPluginDefinition();
         }
     } catch (DatabaseExceptionWrapper $e) {
         // Once we begin iterating the source plugin it is possible that the
         // source tables will not exist. This can happen when the
         // MigrationPluginManager gathers up the migration definitions but we do
         // not actually have a Drupal 6 source database.
     }
     return $this->derivatives;
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target, $hook = NULL, $index = 0, $rewriter_id = NULL)
 {
     $indexer = $target->getIndexer('function');
     if (isset($hook)) {
         if ($indexer->has($hook)) {
             if (empty($rewriter_id)) {
                 // Extract the entity type from the hook (e.g. 'hook_node_delete').
                 preg_match('/^hook_(.+)_[a-z]+$/', $hook, $matches);
                 $rewriter_id = '_rewriter:' . $matches[1];
             }
             $rewriter = $this->rewriters->createInstance($rewriter_id);
             $this->rewriteFunction($rewriter, $indexer->get($hook)->getParameterAtIndex($index), $target);
         }
     } else {
         $this->convert($target, 'hook_comment_delete');
         $this->convert($target, 'hook_comment_insert');
         $this->convert($target, 'hook_comment_presave');
         $this->convert($target, 'hook_comment_update');
         $this->convert($target, 'hook_node_access');
         $this->convert($target, 'hook_node_access', 2, '_rewriter:account');
         $this->convert($target, 'hook_node_access_records', 0, '_rewriter:node');
         $this->convert($target, 'hook_node_access_records_alter', 1, '_rewriter:node');
         $this->convert($target, 'hook_node_delete');
         $this->convert($target, 'hook_node_grants', 0, '_rewriter:account');
         $this->convert($target, 'hook_node_grants_alter', 1, '_rewriter:account');
         $this->convert($target, 'hook_node_insert');
         $this->convert($target, 'hook_node_presave');
         $this->convert($target, 'hook_node_revision_delete');
         $this->convert($target, 'hook_node_search_result');
         $this->convert($target, 'hook_node_submit');
         $this->convert($target, 'hook_node_submit', 2, 'form_state');
         $this->convert($target, 'hook_node_update');
         $this->convert($target, 'hook_node_update_index');
         $this->convert($target, 'hook_node_validate');
         $this->convert($target, 'hook_node_validate', 2, 'form_state');
         $this->convert($target, 'hook_taxonomy_term_delete');
         $this->convert($target, 'hook_taxonomy_term_insert');
         $this->convert($target, 'hook_taxonomy_term_presave');
         $this->convert($target, 'hook_taxonomy_term_update');
         $this->convert($target, 'hook_user_delete');
         $this->convert($target, 'hook_user_logout');
     }
 }
Пример #27
0
 /**
  * {@inheritdoc}
  */
 public function getIndexer($which)
 {
     if (empty($this->indexers[$which])) {
         /** @var IndexerInterface $indexer */
         $indexer = $this->indexerManager->createInstance($which);
         $indexer->bind($this);
         $this->indexers[$which] = $indexer;
     }
     return $this->indexers[$which];
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 public function getNegotiationMethodInstance($method_id)
 {
     if (!isset($this->methods[$method_id])) {
         $instance = $this->negotiatorManager->createInstance($method_id, array());
         $instance->setLanguageManager($this->languageManager);
         $instance->setConfig($this->configFactory);
         $instance->setCurrentUser($this->currentUser);
         $this->methods[$method_id] = $instance;
     }
     return $this->methods[$method_id];
 }
Пример #29
0
 /**
  * {@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;
 }
Пример #30
0
 /**
  * Form constructor.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return array
  *   The form structure.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $constraint_id = NULL, $machine_name = NULL)
 {
     $this->machine_name = $machine_name;
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     /** @var $policy \Drupal\password_policy\Entity\PasswordPolicy */
     $policy = $cached_values['password_policy'];
     if (is_numeric($constraint_id)) {
         $id = $constraint_id;
         $constraint_id = $policy->getConstraint($id);
         $instance = $this->manager->createInstance($constraint_id['id'], $constraint_id);
     } else {
         $instance = $this->manager->createInstance($constraint_id, []);
     }
     /** @var $instance \Drupal\password_policy\PasswordConstraintInterface */
     $form = $instance->buildConfigurationForm($form, $form_state);
     if (isset($id)) {
         // Conditionally set this form element so that we can update or add.
         $form['id'] = ['#type' => 'value', '#value' => $id];
     }
     $form['instance'] = ['#type' => 'value', '#value' => $instance];
     $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#ajax' => ['callback' => [$this, 'ajaxSave']]];
     return $form;
 }