Problem/Motivation

#2830016: Add a thumbnail/icon field to Paragraphs type added an icon filed to Paragraphs Types. However, the files to be used as icons uploaded through the form element it adds (in admin/structure/paragraphs_type/{paragraphs_type}) are temporary. (\Drupal\file\Entity\File::isTemporary returns TRUE for these files.) Thus, Drupal deletes the icons after a while.

Proposed resolution

Adjust ParagraphsType to properly save the icon files as permanent. To achieve this add file usage registration and deregistration through the file.usage service as appropriate.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#28 paragraphs_type_icons-2870989-28.patch7.06 KBVladimirMarko
#23 paragraphs_type_icons-2870989-23.patch7.06 KBVladimirMarko
#23 interdiff-2870989-18-23.txt683 bytesVladimirMarko
#23 paragraphs_type_icons-2870989-23-test-only.patch4.28 KBVladimirMarko
#18 paragraphs_type_icons-2870989-18.patch7.07 KBVladimirMarko
#18 interdiff-2870989-12-18.txt1.04 KBVladimirMarko
#18 paragraphs_type_icons-2870989-18-test-only.patch4.28 KBVladimirMarko
#12 paragraphs_type_icons-2870989-12.patch7.13 KBVladimirMarko
#12 interdiff-2870989-8-12.txt2.91 KBVladimirMarko
#12 paragraphs_type_icons-2870989-12-test-only.patch4.28 KBVladimirMarko
#8 paragraphs_type_icons-2870989-8.patch7.14 KBVladimirMarko
#8 interdiff-2870989-4-8.txt1.75 KBVladimirMarko
#8 paragraphs_type_icons-2870989-8-test-only.patch4.2 KBVladimirMarko
#4 paragraphs_type_icons-2870989-4.patch5.38 KBVladimirMarko
#4 paragraphs_type_icons-2870989-4-test-only.patch2.45 KBVladimirMarko
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VladimirMarko created an issue. See original summary.

VladimirMarko’s picture

Issue summary: View changes
VladimirMarko’s picture

Issue summary: View changes

The last submitted patch, 4: paragraphs_type_icons-2870989-4-test-only.patch, failed testing.

The last submitted patch, 4: paragraphs_type_icons-2870989-4-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: paragraphs_type_icons-2870989-4.patch, failed testing.

The last submitted patch, 8: paragraphs_type_icons-2870989-8-test-only.patch, failed testing.

The last submitted patch, 8: paragraphs_type_icons-2870989-8-test-only.patch, failed testing.

Ginovski’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/ParagraphsType.php
    @@ -84,14 +86,9 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
    +    $icon_uuid = $this->icon_uuid;
    +    if ($icon_uuid && $icon = $this->getFileByUuid($icon_uuid)) {
    

    No need for new variable here, just use $this->icon_uuid

  2. +++ b/src/Tests/Classic/ParagraphsTypesTest.php
    @@ -60,6 +72,12 @@ class ParagraphsTypesTest extends ParagraphsTestBase {
    +    $this->drupalGet('admin/content/files');
    +    $this->assertLink('image-test.png');
    +    $this->clickLink('1 place');
    

    You could add an assertion for the permanent status here.

  3. +++ b/src/Entity/ParagraphsType.php
    @@ -167,4 +164,56 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
    +      $new_icon_uuid = $this->icon_uuid;
    

    Same for this, no need for this new variable, it is only used once.

  4. +++ b/src/Entity/ParagraphsType.php
    @@ -167,4 +164,56 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
    +      if ($update) {
    

    This should be moved outside, it is nested in the opposite if statement(!update).
    Or better, you can remove it and just leave the delete usage of the old icon inside the opposite if statement(!update).

  5. +++ b/src/Entity/ParagraphsType.php
    @@ -167,4 +164,56 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
    +        $old_icon_uuid = $this->original->icon_uuid;
    +        if ($old_icon_uuid && $old_icon = $this->getFileByUuid($old_icon_uuid)) {
    

    After you make the previous change, you will have to check if isset($this->original) here. Because when creating a new paragraph type, there is no original and this displays warning message.

VladimirMarko’s picture

Ginovski’s picture

Status: Needs review » Reviewed & tested by the community

RTBC +1

The last submitted patch, 12: paragraphs_type_icons-2870989-12-test-only.patch, failed testing.

The last submitted patch, 12: paragraphs_type_icons-2870989-12-test-only.patch, failed testing.

VladimirMarko’s picture

Assigned: Unassigned » VladimirMarko
Berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Entity/ParagraphsType.php
@@ -167,4 +163,53 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
+   * @return \Drupal\file_entity\FileEntityInterface|null
+   *  The file entity. NULL if the UUID is invalid.
+   */
+  protected function getFileByUuid($uuid) {
+    if ($uuid) {

file_entity is an optional contrib module. We don't want to type hint on that but FileInterface in core. Also, as discussed, $uuid shouldn't be allowed to be NULL and should never becalled as NULL in the patch. Update the type and remove the if () check.

The last submitted patch, 18: paragraphs_type_icons-2870989-18-test-only.patch, failed testing.

The last submitted patch, 18: paragraphs_type_icons-2870989-18-test-only.patch, failed testing.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

$files_array is a bit uncommon, usually we just use $files or so, but fine.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: paragraphs_type_icons-2870989-18.patch, failed testing.

The last submitted patch, 23: paragraphs_type_icons-2870989-23-test-only.patch, failed testing.

The last submitted patch, 23: paragraphs_type_icons-2870989-23-test-only.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: paragraphs_type_icons-2870989-23.patch, failed testing. View results

Primsi’s picture

It seems that this needs a re-roll :/

VladimirMarko’s picture

  • Primsi committed e94f069 on 8.x-1.x authored by VladimirMarko
    Issue #2870989 by VladimirMarko, Ginovski, Berdir: Paragraphs Type icons...
Primsi’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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