Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-29998: As a developer, I want to define icons for content types #804

Merged
merged 12 commits into from
Jan 29, 2019
Merged

EZP-29998: As a developer, I want to define icons for content types #804

merged 12 commits into from
Jan 29, 2019

Conversation

adamwojs
Copy link
Member

@adamwojs adamwojs commented Jan 17, 2019

Question Answer
Tickets https://jira.ez.no/browse/EZP-29998
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? yes
License GPL-2.0

Example configuration

ezpublish:
    system:
       default:
           content_type:
              article:
                 thumbnail: '/assets/images/customarticle.svg'
              poll:
                 thumbnail: '/assets/images/poll.svg'

Using content type icons in Twig templates

Content type icons are accessible in Twig templates via ez_content_type_icon function which requires content type or content type identifier as an argument and returns path to content type icon.

<svg class="ez-icon ez-icon-{{ contentType.identifier }}">
    <use xlink:href="{{ ez_content_type_icon(contentType.identifier) }}"></use>
</svg>

If the icon for given content type wasn't specified in the configuration then path default icon will be returned.

Default content type icon

A configuration of the default icon for content types is possible via default-config key. For example:

ezpublish:
    system:
       default:
           content_type:
              default-config:
                 thumbnail: '/assets/images/mydefaulticon.svg'

Using content type icons in JS

Icons confgiguration is pushed from the backend as as part of the global configuration eZ.adminUiConfig.contentTypes.

However, more convenient way of retrieving icon would be to use new helper function getContentTypeIcon, which takes content type identifier as argument. It belongs to global object eZ.helpers.contentType.

Example with getContentTypeIcon:

const contentTypeIcon = eZ.helpers.contentType.getContentTypeIcon(contentTypeIdentifier);

return (
    <svg className="ez-icon">
        <use xlinkHref={contentTypeIcon} />
    </svg>
);

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

@tischsoic tischsoic changed the title EZP-29998: As a developer, I want to define icons for content types [WIP] EZP-29998: As a developer, I want to define icons for content types Jan 17, 2019
@lserwatka
Copy link
Member

lserwatka commented Jan 17, 2019

We might need to rethink naming for this function ezplatform_admin_ui_content_type_icon

I would suggest something like ez_render_icon, ez_ui_content_type_icon, or ez_content_type_icon

@adamwojs adamwojs changed the title [WIP] EZP-29998: As a developer, I want to define icons for content types EZP-29998: As a developer, I want to define icons for content types Jan 21, 2019
@adamwojs
Copy link
Member Author

PR updated with the following changes:

  • Renamed twig helper function to ez_content_type_icon according to @lserwatka suggestion
  • ez_content_type_icon returns url decorated by assets component
  • Fixed configuration overwrite bug

@@ -21,6 +21,10 @@ imports:
- { resource: services/permissions.yml }
- { resource: services/forms.yml }

parameters:
# default content type icon
ezsystems.ezplatform_admin_ui.default_content_type_thumbnail: '/bundles/ezplatformadminui/img/ez-icons.svg#file'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 'file' is default content type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was specified in the task (https://jira.ez.no/browse/EZP-29998) description:

In case of a custom content type without defined custom icons, then the file icon from admin-ui will be used.

@@ -162,6 +162,7 @@
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/helpers/request.helper.js'
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/helpers/notification.helper.js'
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/helpers/timezone.helper.js'
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/helpers/content.type.icon.helper.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this just content.type.helper.js because in the addConfig() the group for those methods is helpers.contentType, which implies there will be different methods for content types not only of the icon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the same and I agree.

/**
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver
* @param \Symfony\Component\Asset\Packages $packages
* @param string|null $defaultThumbnail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc does not match constructor parameter.

Similiar tihing seems to be in getContentTypeIcon method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c10c434

$contentType = $contentType->identifier;
}

$thumbnail = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here could be $thumbnail = $this->defaultThumbnail; and the if empty($thumbnail) is not needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. If you configure null or empty string as the content type icon then default icon should be used.

public function getContentTypeIcon($contentType): ?string
{
if ($contentType instanceof ContentType) {
$contentType = $contentType->identifier;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks odd one time under the $contentType is ContentType object and once is the identifier. The ContentType seems to be not needed here so getContentTypeIcon() shouldn't take just string with an identifier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c10c434

@adamwojs
Copy link
Member Author

PR updated according to @ViniTou and @dew326 suggestions.

*
* @return string|null
*/
public function getContentTypeIcon(string $contentType): ?string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$contentTypeIdentifier or just $identifier?

@mikadamczyk
Copy link
Contributor

As we talked, we can add the configuration for the default icon as part of the content_type configuration.

@adamwojs
Copy link
Member Author

As we talked, we can add the configuration for the default icon as part of the content_type configuration.

Done in 3b91172: default configuration is available under default-config key.

I also added unit tests for EzSystems\EzPlatformAdminUi\UI\Service\ContentTypeIconResolver.

{
private const DEFAULT_IDENTIFIER = 'default-config';
private const PARAM_NAME_FORMAT = 'content_type.%s';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this empty line?

Copy link
Contributor

@m-tyrala m-tyrala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA approve

@lserwatka lserwatka merged commit eee23b4 into ezsystems:master Jan 29, 2019
@lserwatka
Copy link
Member

@DominikaK this should be documented.

konradoboza pushed a commit to konradoboza/ezplatform-admin-ui that referenced this pull request May 29, 2019
…zsystems#804)

* EZP-29998: As a developer, I want to define icons for content types

* fixup! EZP-29998: As a developer, I want to define icons for content types

* fixup! EZP-29998: As a developer, I want to define icons for content types

* Add JS helper function returning content type icon href.

* Fix jsDoc comment

* Add default content_type icons for in-house Content Types

* Fix content type icon helper

* fixup! EZP-29998: As a developer, I want to define icons for content types

* Applied CR suggestions

* fixup! Applied CR suggestions

* Fix JS - CR

* fixup! EZP-29998: As a developer, I want to define icons for content types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

7 participants