Improve icon selection in paragraphs type form.

Created on 21 February 2017, about 8 years ago
Updated 1 February 2024, about 1 year ago

Problem/Motivation

Follow-up from #2830016: Add a thumbnail/icon field to Paragraphs type . Uploading a file for each paragraph type has several issues:

  • Uploading icons is not very user friendly.
  • No way to reuse icons.
  • No way to add a separate icon for each theme.
  • Issues with exporting / importing icon configuration.

Proposed resolution

Let's discuss here how we want to improve this.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Needs review

Version

1.0

Component

User interface

Created by

🇷🇸Serbia toncic

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    180 pass
  • Re-rolled patch against latest 8.x-1.x-dev branch.

  • 🇩🇪Germany hctom

    The patch from #17 misses a lot of code changes from #10, therefore hiding it. The MR diff contains all the code changes from #10 and also fixes the deprecated usage of file_create_url(). You should use the MR and its diff instead.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Not currently mergeable.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    180 pass
  • 🇩🇪Germany stborchert

    I rebased branch 2854585-improve-icon-selection with 8.x-1.x and improved the calls to file_create_url() resp. the file_url_generator service.

  • Pipeline finished with Success
    over 1 year ago
    Total: 2133s
    #36926
  • Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Not currently mergeable.
  • 🇩🇪Germany hctom

    Just found a small bug with this patch: The following element is added to ParagraphsTypeForm::form() method's form array by this patch:

    <?php
    $form['static_icon_file']['description'] = [
      '#type' => 'item',
      '#description' => $description,
    ];
    

    Unfortunately an element with '#type' => 'item' is treated as an input value and thus interferes with the form's actual description form field value.

    So my changes add '#input' => FALSE to the new $form['static_icon_file']['description'] element to NOT treat this element as a form value anymore.

  • Pipeline finished with Failed
    about 1 year ago
    Total: 1350s
    #85987
  • 🇨🇦Canada teknocat

    I'd really like a way to set icons that don't have to be uploaded and stored in the files directory. It would be ideal to be able to just specify a path to an icon, so it could be included with the theme. I would also like the option of using something like fontawesome to provide icons, so being able to just put in an HTML tag that displays an icon would be great. Then it's on me to make sure that the icon font is included with the admin theme for the sites I build, which I already do and use in other areas.

  • 🇩🇪Germany stborchert

    @teknocat Hi. Did you had a change to test the merge request we've made?
    After applying the changes you are able to implement hook_paragraphs_type_static_icon_uri_alter() (in a module or theme) where you can set the icon path to wherever you want. The file could be saved in a module, in the a theme, on an external storage, you name it ...

    To use icons provided by fontawesome, you'll nee to override/decorate the ParagraphsTypeListBuilder class and change the way, $row['icon_file']['data'] is build.
    Example (not tested):

    <?php
          $row['icon_file']['data'] = [
            '#theme' => 'html_tag',
            '#tag' => 'span',
            '#attributes' => [
              'class' => ['fa-' . $entity->id()],
            ]
          ];
    ?>

    This will create a <span> tag using the paragraph type ID as fontawesome class.

  • 🇨🇦Canada teknocat

    @stborchert ah ok! Sorry I don't think I fully understood the possibilities with that merge request.

    I'll try that out.

Production build 0.71.5 2024