Problem/Motivation

Currently a workflows state is a fairly limited because it's just an arbitrary object, which is pretty loose and doesn't offer us many benefits.

Proposed resolution

Convert State to a DataType using the TypedData API. This allows us to make use of all TypedData API features as well as related APIs such as Context.

Remaining tasks

- Review
- Tidy
- Test

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

timmillwood created an issue. See original summary.

timmillwood’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
25.78 KB
timmillwood’s picture

FileSize
26.78 KB

Think I'm missing some files.

The last submitted patch, 2: 2846335-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: 2846335-3.patch, failed testing.

timmillwood’s picture

Not sure why this broke the translation test.

Sam152’s picture

Can the deleted lines in test be ported instead of deleted? Is there a reason they are no longer relevant?

timmillwood’s picture

@Sam152 - I expect they can be ported, the issue is they depend on TypedDataManager, which makes unit tests a bit more complex.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sam152’s picture

Issue tags: +Needs tests

I wonder if there is a concrete use case for this change that can be included with the patch to demonstrate why it's valuable.

Also, do transitions need the same treatment? Maybe a real world "this will allow us to achieve..." would help answer that question.

timmillwood’s picture

I guess transitions could have it in the future.

I came to wanting states to be data types to be able to do new Context(new ContextDefinition('state'), $state); and use state as a context. Then the more I thought about it, it just seemed to make sense. Drupal has this inbuilt thing for defining types of stuff, but we just create an arbitrary State class.

Sam152’s picture

Maybe @alexpott should weigh in on the design patterns, being the author. Value objects would seem to have a place here but seems reasonable to use a Drupal abstraction if the shoe fits.

I came to wanting states to be data types to be able to do new Context(new ContextDefinition('state'), $state); and use state as a context.

What was this for? Filtering a view by some state? Passing it into some other context?

timmillwood’s picture

I was thinking one use for context would be within the access handler when deleting states, we'll know the state from the context.

Sam152’s picture

Could we add the state context to the access checks as part of the patch to demonstrate the usefulness? Could be a useful DX addition regardless of the core use of it.

tacituseu’s picture

Component: content_moderation.module » workflows.module
bojanz’s picture

-1.

Value objects are simple, and can be instantiated directly through code.
DataTypes can't be instantiated directly, and are harder to understand.
This patch adds a big DX regression just to simplify context passing.

timmillwood’s picture

Status: Needs work » Closed (outdated)
geek-merlin’s picture

Title: Convert Workflows State to a DataType » Add a Workflows State / DataType Adapter
Status: Closed (outdated) » Needs work

I support bojan's point. And no need to give this up then. Look into entities, they *are* no typed data, but can be wrapped to typed date via EntityAdapter class.

Version: 8.4.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.