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().
Issue fork display_builder-3618945
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
Comment #2
pdureau commentedComment #4
pdureau commentedDone:
Pipeline is green.
Todo:
Comment #5
pdureau commentedDone:
::getCurrentState()to::getSources()InstanceInterface::getBuildablePlugin()instead of usingFieldableEntityInterface::get()Instance::refreshContexts()andDisplayBuilderHelpers::markSampleEntity()Comment #6
mogtofu33 commentedCould you check for a rebase please.
Comment #7
mogtofu33 commentedI will handle rebase as I have this with perhaps #3573905: Simplify DisplayBuildableInterface
Comment #9
mogtofu33 commentedRebased, merged and added architecture cleanup