4 proposals to simplify Instance entity.

Rename ::getCurrentState()

"Current state" of a concept from the State Manager era of the project, before the move to revisionable entities.

Everywhere else, we use ::getSources(), so let's do the same here.

Add ::getBuildable()?

When I have added the buildable field in Instance entity, I was initially against exposing it to the public interface because it was an implementation detail, internal to the entity.

However, after a few months, it seems it not the case, and are overusing FieldableEntityInterface::get() to load the plugin.

Twice in InstanceListBuilder:

    /** @var \Drupal\display_builder\Plugin\Field\FieldType\PluginItem $item */
    $item = $instance->get('buildable')->first();
    /** @var \Drupal\display_builder\DisplayBuildableInterface $buildable */
    $buildable = $item->getInstance();
    $type = $buildable->label() ?? '-';

    /** @var \Drupal\display_builder\Plugin\Field\FieldType\PluginItem $field */
    $field = $entity->get('buildable')->first();
    /** @var \Drupal\display_builder\DisplayBuildableInterface $buildable */
    $buildable = $field->getInstance()

Once in ApiPreviewController:

    /** @var \Drupal\display_builder\Plugin\Field\FieldType\PluginItem|null $item */
    $item = $instance->get('buildable')->first();
    /** @var \Drupal\display_builder\DisplayBuildableInterface|null $buildable */
    $buildable = $item?->getInstance();
    $path = $buildable?->getPreviewPagePath();

Once in StateButtons

    /** @var \Drupal\display_builder\Plugin\Field\FieldType\PluginItem|null $item */
    $item = $instance->get('buildable')->first();
    /** @var \Drupal\display_builder\DisplayBuildableInterface|null $buildable */
    $buildable = $item?->getInstance();

    if ($buildable instanceof DisplayBuildableOverrideInterface) {
      return !empty($buildable->getSources());

Once in ProfileViewBuilder:

$buildable_id = $builder->get('buildable')->first()->get('plugin_id')->getValue() ?? '';

So, let's add a ::getBuildable() public method.

Do we keep ::getProfile(), ::getRuntimeContexts(), ::getAvailableContexts() ?

Remove ::getPathIndex()?

It seems it is used only in tests: InstanceTest, InstanceHistoryTest, & InstanceMoveToSlotTest

Remove Instance::refreshContexts()

While working on #3618072: Placeholders and real render, in Canvas and Preview, we asked ourselves why do we have Instance::refreshContexts()? Is it a leftover of previous architecture (before the buildable plugins) ?

There is nothing related to, or own by, the instance data in this method. Once #3544026: Cardinality constraints for slots wil lbe merged, it will seem the logic can be moved to EntityView, alongside ::markSampleEntity().

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

Issue summary: View changes

pdureau’s picture

Issue summary: View changes
Status: Active » Needs work

Done:

Pipeline is green.

Todo:

  • Do we keep ::getProfile(), ::getRuntimeContexts(), ::getAvailableContexts() ?
  • Remove ::getPathIndex()?
pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

Done:

  • Rename ::getCurrentState() to ::getSources()
  • Add InstanceInterface::getBuildablePlugin() instead of using FieldableEntityInterface::get()
  • Remove Instance::refreshContexts() and DisplayBuilderHelpers::markSampleEntity()
mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work

Could you check for a rebase please.

mogtofu33’s picture

Assigned: pdureau » mogtofu33

I will handle rebase as I have this with perhaps #3573905: Simplify DisplayBuildableInterface

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs work » Fixed

Rebased, merged and added architecture cleanup

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mogtofu33 committed 0ea2e0e5 on 1.0.x
    task: #3618945 Tidy Instance methods, #3573905 publish() rename,...