-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
We might need to rethink naming for this function I would suggest something like |
PR updated with the following changes:
|
@@ -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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c10c434
* | ||
* @return string|null | ||
*/ | ||
public function getContentTypeIcon(string $contentType): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$contentTypeIdentifier
or just $identifier
?
As we talked, we can add the configuration for the default icon as part of the |
Done in 3b91172: default configuration is available under I also added unit tests for |
{ | ||
private const DEFAULT_IDENTIFIER = 'default-config'; | ||
private const PARAM_NAME_FORMAT = 'content_type.%s'; | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA approve
@DominikaK this should be documented. |
…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
Example configuration
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.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: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 objecteZ.helpers.contentType
.Example with getContentTypeIcon:
Checklist:
$ composer fix-cs
)