Problem/Motivation

Either add a refresh button in the custom_elements_ui submodule in the EntityCustomElementsDisplayEditForm or add dynamic refresh with ajax.

preview

CommentFileSizeAuthor
sc-251006-1608.png143.62 KBuseernamee
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

useernamee created an issue. See original summary.

useernamee’s picture

useernamee’s picture

I'm a bit stuck with refreshing because the preview custom element (in ce display entity form) is build with

      ...
      $ce_display = clone $this->getEntity();
      ...
      $this->copyFormValuesToEntity($ce_display, $form, $form_state);
      ...
      $entity_type_id = $ce_display->getTargetEntityTypeId();
      $bundle = $ce_display->getTargetBundle();
      $sample = $this->generateSampleEntity($entity_type_id, $bundle);
      $preview['content'] = $this->getCustomElementGenerator()->generate($sample, $ce_display->getMode())->preview();

The ce_display has values from the last form save and not from the last edit, until I call the copyFormValuesToEntity. This updates ce_display but it doesn't have effect because Custom Element is generated only with the $ce_display->getMode() which is the last save ce display again.

What we're missing is a method to generate Custom Element out of $ce_display directly.

useernamee’s picture

I overcome the issue by slightly adjusting the API from CustomElementsGenerator. NR

useernamee’s picture

Status: Active » Needs review
fago’s picture

Title: Refresh ce display preview » Add button to refresh ce display preview
Status: Needs review » Needs work

Thanks! I commented https://git.drupalcode.org/project/custom_elements/-/merge_requests/139 - please take a look.

> What we're missing is a method to generate Custom Element out of $ce_display directly.
yeah, let's introduce it then, as a separte method + make the existing method call the new helper?

useernamee changed the visibility of the branch 3551209-refresh-ce-display to hidden.

useernamee changed the visibility of the branch 3551209-refresh-ce-display to active.

useernamee’s picture

Status: Needs work » Needs review
fago’s picture

Status: Needs review » Needs work

thx, that looks mostly great now! I've found case where I think we should throw an exception though, see MR. Could you check that?

useernamee’s picture

Status: Needs work » Needs review

fixed

fago’s picture

Status: Needs review » Needs work

MR looks good. However, when testing changes I do not see the button?

The preview is refreshed when changing formatter settings, but when e.g. renaming a field in output, I don't have a way to update the preview still? So something seems not right here.

fago’s picture

One more though. Maybe we should do it similar to Views, and simply have a preview-area that is always there + a button to make it load? Since we need the button to make it load anyway, the fieldset wrapper seems unnecessary. Then we could add a drop-down to select the desired preview-provider also. --> for the dropdown we need not use the plugins but get the list of provider-services from our provider-resolver.

useernamee’s picture

Status: Needs work » Needs review

@fago maybe it would be better to create a follow up for dropdown to select preview provider.

  • fago committed 3362eb93 on 3.x authored by useernamee
    feat: #3551209 Add button to refresh ce display preview
    
    By: useernamee
    
fago’s picture

Status: Needs review » Fixed

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.