Problem/Motivation

As a carry over from Configuration Packager, currently we model config in FeaturesManager::configCollection as a structured array. A piece of configuration has a complex set of properties and FeaturesManager includes several methods related to configuration items. It would be more consistent and appropriate to model configuration items as a custom object type.

Proposed resolution

Create a new FeaturesConfigurationItem object. TBD: is there any existing core object we should consider extending?

Model existing array keys as properties.

Identify methods to move from FeaturesManager to FeaturesConfigurationItem. Candidates:

  • ::getFullName()
  • ::getConfigType()

Remaining tasks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nedjo created an issue. See original summary.

nedjo’s picture

Title: Remodel packages as objects » Remodel configuration items in FeaturesManager::configCollection as objects
mpotter’s picture

This would be worthwhile and would also cause API changes, so need to do this before beta.

dawehner’s picture

FileSize
11.1 KB

This is just a quick start so far:

* One fundamental question: should we deal with an immutable object?
* Should we keep an ArrayAccess for now or should everything be converted ...

dawehner’s picture

FileSize
11.67 KB

Some small updates

nedjo’s picture

Great start, thanks!

should we deal with an immutable object?

We make changes to items in the config collection in assignment plugins, so I'm assuming not.

Should we keep an ArrayAccess for now or should everything be converted

I guess for clarity it makes more sense to convert to using object property notation?

dawehner’s picture

I guess for clarity it makes more sense to convert to using object property notation?

I mean on the longrun this is for sure, but I'm curious whether we should keep the array object in order to keep the issue limited.
Currently looking at some conversions.

dawehner’s picture

Status: Active » Needs review
FileSize
34.42 KB
23.08 KB

Some more work with an additional todo, should this value object have an interface? Personally I think this should be avoided as long as possible.

nedjo’s picture

Looking great.

Can we now remove these methods and replace calls to them with calls to equivalent ConfigurationItem methods?

  • FeaturesManager::getFullName()
  • FeaturesManager::getConfigType()

If so, should we wait and do that as a followup patch?

dawehner’s picture

In general I'm a huge fan in incremental approaches, even they introduce temporarily non optional approaches.
Happy to work on extracting those helper methods though, i'll do that in a local branch so splitting up will be easy.

dawehner’s picture

Identify methods to move from FeaturesManager to FeaturesConfigurationItem. Candidates:

::getFullName()
::getConfigType()

So I was wondering whether there should be a

  • SimpleConfigurationItem
  • ConfigEntityConfigurationItem

to distinct the logic.

Another question which you could ask, should this object really have everything as a big list of constructor arguments or should there be an array of properties like on \Drupal\Core\Entity\EntityType itself.

nedjo’s picture

In general I'm a huge fan in incremental approaches

Agreed. Let's aim to do the minimum first step here.

So I was wondering whether there should be a

  • SimpleConfigurationItem
  • ConfigEntityConfigurationItem

To avoid some of the conditional logic built into methods like FeaturesManager::getFullName()? They would extend a common base class? Sounds like a worthwhile refinement, though maybe one we could leave for followup?

should there be an array of properties like on \Drupal\Core\Entity\EntityType itself.

That sound good to me, with, probably, accompanying ::get() and ::set() methods equivalent to EntityType::get() and EntityType::set() rather than a distinct getter/setter for each property.

dawehner’s picture

To avoid some of the conditional logic built into methods like FeaturesManager::getFullName()? They would extend a common base class? Sounds like a worthwhile refinement, though maybe one we could leave for followup?

Yeah something like that, but sure, it should be in a followup.

That sound good to me, with, probably, accompanying ::get() and ::set() methods equivalent to EntityType::get() and EntityType::set() rather than a distinct getter/setter for each property.

Not sure whether we need get/set(). Afaik this is there to accomplish the feature to add arbitrary entity metadata which I think features won't need?

Currently on fixing the tests locally.

dawehner’s picture

Alright, fixed the test.

mpotter’s picture

This is looking pretty good. My only concern is that giant constructor and the effect that has on creating new config objects. There is an awful lot of '', NULL, [] kind of magic arguments being passed which makes it very hard to read. It also makes it hard to maintain when new properties are added to this object.

I think a better approach might be to have the setter methods return the config object itself. Then make the constructor take the minimum (if any) arguments. Then you could have code that could convert the existing:

    $config_collection['example.config2'] = new ConfigurationItem('example.config2', [
      'dependencies' => [],
    ], '', '', '', [], '', 'package2', TRUE, 'my_feature');

into something more like this:

$config_collection['example.config2'] = new ConfigurationItem('example.config2')
  ->setData(['dependencies' => []])
  ->setPackage('package2')
  ->setProvidingFeature('my_feature')

Or something like that.

dawehner’s picture

FileSize
36.05 KB
2.85 KB

What about enabling both?

Status: Needs review » Needs work

The last submitted patch, 16: 2595265-16.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
36.04 KB
2.27 KB

Ha, its great to have some form of tests!

mpotter’s picture

+++ b/src/FeaturesManager.php
@@ -948,12 +953,10 @@ class FeaturesManager implements FeaturesManagerInterface {
+          $config_collection[$name] = (new ConfigurationItem($name, $data, [

Minor nit-pick, but do we actually need the extra () around the "new ConfigurationItem..." statement?

Otherwise, I really like this dual approach! Moving the extra properties into an array argument was also much better and more extensible for the future. I'll apply this patch and test it today.

dawehner’s picture

FileSize
36.04 KB
897 bytes

Oh yeah, they aren't needed at all, unless you want to put additional function calls inline.

mpotter’s picture

Status: Needs review » Fixed

OK, did some testing and this looks good, so committed it to c06283e.

Now that it is refactored we can add some additional unit tests for it.

mpotter’s picture

Oops, missed a couple that I forgot to push from my testing. Fixed in commit b72e60b.

  • mpotter committed b72e60b on 8.x-3.x
    Issue #2595265 by dawehner, mpotter: Remodel configuration items in...
  • mpotter committed c06283e on 8.x-3.x authored by dawehner
    Issue #2595265 by dawehner: Remodel configuration items in...

  • mpotter committed b663ee1 on 8.x-3.x
    Revert "Issue #2595265 by dawehner, mpotter: Remodel configuration items...
  • mpotter committed c7a3f55 on 8.x-3.x
    Revert "Issue #2595265 by dawehner: Remodel configuration items in...
mpotter’s picture

Status: Fixed » Needs work

OK, sorry, my bad. This still needs some work. I reverted the commits and will continue to test more and work on it.

dawehner’s picture

@mpotter
Yeah I could totally imagine bits which aren't perfect :(

mpotter’s picture

Status: Needs work » Needs review
FileSize
34.34 KB
10.8 KB

OK, here is a new patch for somebody else to also test and review. Included an interdiff of what I had to fix vs #20.

mpotter’s picture

Note, that it might be good to refactor the $manager->getConfigType() function to also return a configuration item instead of array since it causes some inconsistent code that is hard to maintain.

nedjo’s picture

Status: Needs review » Needs work

ConfigurationItem.php file is missing from the patch.

mpotter’s picture

Status: Needs work » Needs review
FileSize
39.81 KB

Ooops. Try this.

  • nedjo committed 7c9f2f0 on 8.x-3.x authored by dawehner
    Issue #2595265 by dawehner, mpotter: Remodel configuration items in...
nedjo’s picture

Status: Needs review » Needs work

@dawehner, @mpotter: nice work!

Ran through its paces, no issues showed up. One more beta blocker down :)

Setting to "needs work" because after I committed this I noticed a missed change in FeaturesManager::reset() (should call $config->setPackage()):

    foreach ($this->configCollection as &$config) {
      $config['package'] = NULL;
    }
dawehner’s picture

Status: Needs work » Needs review
FileSize
2.26 KB

Good observation, here is a test.

  • nedjo committed a5912ac on 8.x-3.x authored by dawehner
    Issue #2595265 by dawehner: Fix configCollection iteration in...
nedjo’s picture

Status: Needs review » Fixed

Applied, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

The last submitted patch, 27: 2595265-27.patch, failed testing.

The last submitted patch, 30: 2595265-30.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 33: 2595265-33.patch, failed testing.

nedjo’s picture

Status: Needs work » Closed (fixed)