Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2504031: Fix __construct of plugin to be compatible with D8 Plugins #51

Merged
merged 5 commits into from
Jun 16, 2015
Merged

Issue #2504031: Fix __construct of plugin to be compatible with D8 Plugins #51

merged 5 commits into from
Jun 16, 2015

Conversation

drupol
Copy link
Collaborator

@drupol drupol commented Jun 11, 2015

Update code to be compatible with D8.

'arguments' => array()
);

array_unshift($service_definition['arguments'], $configuration);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move all of this into the caller (ContainerAwarePluginManager::createInstance)

@dawehner
Copy link
Collaborator

Mh I think its odd to expose the plugin information on a container

@@ -61,8 +61,7 @@ public function hasDefinition($plugin_id) {
public function createInstance($plugin_id, array $configuration = array()) {
// @todo: Use ->expandArguments() when get() disallows getting private
// services.
$plugin = clone $this->container->get($this->servicePrefix . $plugin_id);
return $plugin;
return $this->container->createInstance($this->servicePrefix . $plugin_id, $configuration);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call this with the $definition instead, get the definition via: $this->getDefinition($plugin_id);

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

Can't get this working.

@@ -218,6 +218,8 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
$this->services[$id] = $service;
}



Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white space change

@LionsAd
Copy link
Owner

LionsAd commented Jun 11, 2015

@dawehner: It is, the definitions should be parameters per plugin manager. (and yes I want that info in the container for now for those plugin managers).

This is a first step into that direction, createInstance is only temporary. I think the real fix is to have get() also take a definition array.

@LionsAd
Copy link
Owner

LionsAd commented Jun 11, 2015

@drupol The code is great. The unit tests fail, because of changed expectations. I will fix them - likely tomorrow.

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

Ok, I will look for it in the meantime ! Thanks for your patience :)

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

If it helps, when I try to run Openlayers with these changes, I get the error:

RuntimeException: The "plugin_openlayers.Map.internal.OLMap" service definition does not exist. in Drupal\service_container\DependencyInjection\Container->get() (line 88 of /home/pol/git/service_container_fork/src/DependencyInjection/Container.php).


array_unshift($plugin_definition['arguments'], $configuration);

return $this->container->createInstance($this->servicePrefix . $plugin_id, $configuration);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOH!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the bug now, need to pass $plugin_definition and not $configuration here ...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drupol ^^

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

Now I don't have any errors and it seems that it has fixed a couple of things. BUT... I have now plenty of:

Warning: Missing argument 3 for Drupal\openlayers\Types\Object::__construct(), called in /home/pol/git/service_container_fork/src/DependencyInjection/Container.php on line 154 and defined in Drupal\openlayers\Types\Object->__construct() (line 88 of /home/pol/git/openlayers/src/Types/Object.php).
Notice: Undefined index: plugin module in Drupal\openlayers\Types\Object->__construct() (line 90 of /home/pol/git/openlayers/src/Types/Object.php).
Notice: Undefined index: plugin type in Drupal\openlayers\Types\Object->__construct() (line 90 of /home/pol/git/openlayers/src/Types/Object.php).
Notice: Undefined index: name in Drupal\openlayers\Types\Object->__construct() (line 90 of /home/pol/git/openlayers/src/Types/Object.php).
Warning: Missing argument 3 for Drupal\openlayers\Types\Object::__construct(), called in /home/pol/git/service_container_fork/src/DependencyInjection/Container.php on line 154 and defined in Drupal\openlayers\Types\Object->__construct() (line 88 of /home/pol/git/openlayers/src/Types/Object.php).

I will look for them at home.

@LionsAd
Copy link
Owner

LionsAd commented Jun 11, 2015

@drupol Yes, that is the BC break I talked about.

We should break BC some more before you fix it ;).

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

No problem :)

@LionsAd
Copy link
Owner

LionsAd commented Jun 11, 2015

To break BC some more we should use:

  • $configuration
  • $plugin_id
  • $plugin_definition (already in arguments as first part)
  • any further parameters

As the first parameters.

That means array_unshift the plugin_id first and then the configuration.

Great work!

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

It works if I do some change in the constructor of my OL objects:

  /**
   * Constructs a Drupal\Component\Plugin\PluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
    $this->pluginDefinition = $plugin_definition;

    $this->pluginId = $plugin_definition['plugin module'] . '.' . $plugin_definition['plugin type'] . ':' . $plugin_definition['name'];
    $this->configuration = $configuration;
  }

But $configuration is always empty.

@drupol
Copy link
Collaborator Author

drupol commented Jun 11, 2015

Actually, I can now remove the constructor method from Objects.php ! 👍
I don't need the pluginId property.

@LionsAd
Copy link
Owner

LionsAd commented Jun 12, 2015

@drupol We will need a huge change notice both for service_container and openlayers.

I will also have to fix render_cache first.

@LionsAd LionsAd added the RTBM label Jun 12, 2015
@LionsAd LionsAd added Hold and removed Needs review labels Jun 12, 2015
@drupol
Copy link
Collaborator Author

drupol commented Jun 12, 2015

Huge ?
I can take care of it if you give me more informations. Right now, things hasn't changed much in Openlayers, why would it be so huge ? I don't see what you mean.

@LionsAd
Copy link
Owner

LionsAd commented Jun 12, 2015

Triggering a rebuild.

@drupol drupol added this to the 1.0.0 milestone Jun 14, 2015
drupol added a commit that referenced this pull request Jun 16, 2015
…lugins-to-be-compatible-with-Drupal-8

Issue #2504031: Fix __construct of plugins to be compatible with Drupal 8 and take the necessary configuration
@drupol drupol merged commit d0472c4 into LionsAd:7.x-1.x Jun 16, 2015
@drupol drupol changed the title Fix __construct of plugin to be compatible with D8 Issue #2504031: Fix __construct of plugin to be compatible with D8 Plugins Jun 16, 2015
@drupol drupol removed the Hold label Jun 16, 2015
@drupol drupol deleted the Issue-2504031-Fix-__construct-of-plugins-to-be-compatible-with-Drupal-8 branch June 25, 2015 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants