Problem/Motivation

Currently the unpublished access form elements are displayed on every entity form (if entity is publishable and currently unpublished). This does not make sense e.g. on the entity delete form.

Proposed resolution

Only show form elements on relevant forms.

Remaining tasks

  • Create a patch to solve this issue

User interface changes

  • Unpublished access form elements will only be avalailable on entity add/edit forms, but not on delete forms

API changes

n/a

Data model changes

n/a

Comments

hctom created an issue. See original summary.

hctom’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new951 bytes

Here is a patch that filters out entity delete forms for displaying the unpublished access form elements. It may be extended with more form handler keys in the future

chr.fritsch’s picture

Status: Needs review » Needs work

We recently added some similar functionality in content lock #2916747: Consider the form operation when locking. I think it would be much nicer.

moshe weitzman’s picture

Still an issue. Happens on the form for https://www.drupal.org/docs/contributed-modules/scheduled-transitions module as well. Can we limit the alter to just the edit form?

chr.fritsch’s picture

Maybe the same as in #3207607: don't generate permissions for entity types that don't have a canonical link and check if the entity has the canonical link-template?

moshe weitzman’s picture

Yeah, that would fix the problem we have on https://www.mass.gov. Any chance you can roll similar patch here?

chr.fritsch’s picture

I think my suggestion form #5 is only part of the solution here. @moshe could you review #3207607: don't generate permissions for entity types that don't have a canonical link, that should fix the problem at least for you

chr.fritsch’s picture

I had another idea. What about adding some config to entity form displays, where you can choose if the form should be displayed or not for this form?

hctom’s picture

I'm not really sure what you mean by "adding some config to entity form displays", but isn't that what the "Manage Form display" settings are for?! So what about exposing the access unpublished element for that page, so it can be dragged to the position you want to have it... or moved to the "Disabled" section to remove it.

marcoscano’s picture

StatusFileSize
new857 bytes

Came across this as well, where the element is being added in all confirmation forms (delete, replicate, etc). Not sure if I'm missing some scenarios, but here's a patch that takes a more opinionated and simplified approach, only displaying it on entity edit forms.

hctom’s picture

@marcoscano Unfortunately it is not that easy, because form handler keys are totally up to the entity definition. Taxonomy terms for example don't have an edit form handler key and only use the default key. Nodes otherwise use both default and edit form handler keys.

chr.fritsch’s picture

I think that adding a pseudo field with hook_entity_extra_field_info is the best option we have so far.

chrissnyder’s picture

I re-rolled marcoscano's patch from #10 to work with the latest version. While this solution is not perfect, it does resolve the issue I experienced with the form showing on Scheduled Transitions node forms.

alexpott’s picture

I've pushed a fix up to #3164509: Authenticated user can manage unpublished access tokens on node delete page that's pretty similar to the patch in #13 but copies code from the flag module. I think we should re-purpose this issue to do something similar to flag's hook_entity_extra_field_info() so people can hide the form on specific entity type / bundles. Going to credit @ChrisSnyder, @marcoscano and @hctom on the other issue.

mably’s picture

Status: Needs work » Fixed

I think the problem is fixed in current version:

    // Determines if the given form operation is add or edit. Prevents the
    // access unpublished form from being displayed on other random entity
    // forms, for example, the delete form.
    if (!in_array($form_object->getOperation(), ['edit', 'default'], TRUE)) {
      return;
    }

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $form_object->getEntity();

    if (AccessUnpublished::applicableEntityType($entity->getEntityType()) && !$entity->isPublished() && !$entity->isNew()) {

Closing for now. Feel free to reopen if I missed something.

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.

Status: Fixed » Closed (fixed)

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