When editing already placed media entities and you edit them in Gutenberg, but fixing focal point, adding copyright etc. they are not refreshed so you can't see the changes. They are however saved and the changes are there when you view the node.

Issue fork gutenberg-3220331

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

mnlund created an issue. See original summary.

kiss.jozsef’s picture

StatusFileSize
new2.95 KB

I did not find any good way of doing this , but on editing a media there was a custom submit added in the .module already so i added another ajax command which calls a function and in the function we call setAttributes which sets the same data again which causes a refresh so the image change or focal point change (or any other image related change) is shown in the editor on save.

szeidler’s picture

Status: Active » Needs review
codebymikey’s picture

Status: Needs review » Needs work

Thanks for putting in a working patch, I think the solution is sound, but in terms of future-proofing/best practices, I'd suggest not creating the jQuery function specifically in the component constructor, and creating a dedicated Ajax command and reacting to the change accordingly.

jQuery functions are more global and meant to be contextual in most cases.

The function name should also be namespaced (or more accurately prefixed) ideally with the gutenberg name to avoid collision as well as make it easier to know which module it relates to.

Example custom ajax command declaration in JS:

Drupal.AjaxCommands.prototype.gutenbergUpdateMediaEntities = function (ajax, response, status) {
  // Handle logic here.
}

A sample ajax command may be generated using drupal-console's drupal generate:ajax:command command to help get started.

I'd also suggest looking into implementing changes in issue forks as that makes it a lot easier to review and merge in changes.

kiss.jozsef’s picture

StatusFileSize
new4.37 KB

Updated to ajaxcommands instead of jquery function.

szeidler’s picture

Status: Needs work » Needs review

marcofernandes’s picture

Status: Needs review » Fixed
sadeghbayan’s picture

StatusFileSize
new5.72 KB

There is an issue with the provided patch. so when you update the alt text it will add an array inside array so it will be like: [['13056']] and when node is being saved the image will not be shown as its mediaEntityIds attribute is wrong.

I've added a helper function where we can call with the mediaEntityId so it will update/refresh the attributes.

esolitos’s picture

Status: Fixed » Needs work
codebymikey’s picture

Untested, but the code looks good to me. An issue fork would be a much more manageable way of testing and getting it merged in.

+    const { dispatch } = wp.data;
+    const response = await fetch(
+        Drupal.url(`editor/media/render/${id}`),
+    );

One thing that's been on my mind for a while now is the usage of the editor/... namespace for routes across the codebase.
I believe all the routes should be prefixed with gutenberg/ just to avoid any potential collisions with the editor module's internal routing, it also makes it easier to associate the path to the Gutenberg module.

The route stuff is pretty low priority at the moment, but an issue can be created to address it in the future.

  • marcofernandes committed 8adbd23 on 8.x-2.x
    Issue #3220331 by kiss.jozsef, sadeghbayan, szeidler, codebymikey,...

marcofernandes’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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