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 #520

Merged
merged 5 commits into from
Feb 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions docs/guide/extending_ez_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,74 @@ class OrderedTabSubscriber implements EventSubscriberInterface
}
```

## Custom Content Type icons

To add custom icons for existing Content Types or custom Content Types in eZ Platform follow the instructions below.

### Configuration

A configuration of the default icon for Content Type is possible via `default-config` key.
For example:

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

To configure a custom icon you just need to replace the `default-config` key with a Content Type identifier.
For example:

```yaml
ezpublish:
system:
default:
content_type:
article:
thumbnail: '/assets/images/customicon.svg'
```

!!! note "Icons format"

All icons should be in SVG format so they can display properly in Back Office.

### Custom icons in Twig templates

Content Type icons are accessible in Twig templates via `ez_content_type_icon` function.
It requires Content Type identifier as an argument. The function returns the path to a Content Type icon.

```twig
<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 is **not specified** in the configuration the default icon will be returned.

### Custom icons in JavaScript

Content Types icons configuration is stored in a global object: `eZ.adminUiConfig.contentTypes`.

You can easily retrieve icon URL with a helper function `getContentTypeIcon`, set on a global object `eZ.helpers.contentType`.
It takes Content Type identifier as an argument and returns:

- URL of given Content Type's icon or
- `null` if there is no Content Type with given identifier

Example with `getContentTypeIcon`:

```jsx
const contentTypeIconUrl = eZ.helpers.contentType.getContentTypeIconUrl(contentTypeIdentifier);
return (
<svg className="ez-icon">
<use xlinkHref={contentTypeIconUrl} />
</svg>
)
```
Copy link
Contributor

@tischsoic tischsoic Jan 31, 2019

Choose a reason for hiding this comment

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

I would rewrite this part to something like:
(more or less, I'm bad writer, so you can change if you feel that something is not smooth :) )

Content Types icons configuration is stored in global object: eZ.adminUiConfig.contentTypes.

You can easily retrieve icon url with helper function getContentTypeIconUrl(contentTypeIdentifier), set on global object eZ.helpers.contentType. It takes Content Type Identifier as an argument and returns url of given content type's icon or null in case there is no content type with given identifier.

Example:

const contentTypeIconUrl = eZ.helpers.contentType.getContentTypeIconUrl(contentTypeIdentifier);
return (
   <svg className="ez-icon">
       <use xlinkHref={contentTypeIconUrl} />
   </svg>
);


## Workflow event timeline

[Workflow event timeline](workflow.md) is used out of the box to display workflow transitions.
Expand Down