Skip to content

Commit 6e7bf58

Browse files
Add more Plone 6.0 upgrade info.
We missed various PLIPS and other improvements: - `collective.dexteritytextindexer` merged - `plone.base` - modern image scales - image pre scaling - responsive image support - store image scale info in catalog metadata I am giving a presentation next week and was missing some info. :-)
1 parent 59bb7d3 commit 6e7bf58

File tree

1 file changed

+248
-1
lines changed

1 file changed

+248
-1
lines changed

docs/backend/upgrading/version-specific-migration/upgrade-to-60.md

Lines changed: 248 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,251 @@ The same change is needed for the no longer supported `includeDependenciesOverri
294294
```{seealso}
295295
- [PLIP 3339](https://github.com/plone/Products.CMFPlone/issues/3339)
296296
- [`plone.autoinclude`](https://github.com/plone/plone.autoinclude) documentation
297-
```
297+
```
298+
299+
300+
(v60-dexteritytextindexer-label)=
301+
302+
## `collective.dexteritytextindexer` merged
303+
304+
You can mark fields of a content type as searchable.
305+
You can then find an object in the search form by using any text from these fields.
306+
For this to work, you need to enable the `plone.textindexer` behavior on the content type.
307+
For more information, see {ref}`backend-indexing-textindexer-label`.
308+
309+
In earlier Plone versions, this feature was available in the `collective.dexteritytextindexer` package.
310+
This was merged into Plone 6.0 core, with most code ending up in `plone.app.dexterity`.
311+
312+
If you have an add-on or custom code that uses the old package, then this must be upgraded.
313+
These are the needed changes:
314+
315+
- Remove `collective.dexteritytextindexer` from the `install_requires` in `setup.py`.
316+
- Update the Python code of your content type code, like this:
317+
318+
```diff
319+
-from collective import dexteritytextindexer
320+
+from plone.app.dexterity import textindexer
321+
from plone.app.textfield import RichText
322+
from plone.supermodel import model
323+
...
324+
class IExampleType(model.Schema):
325+
- dexteritytextindexer.searchable("text")
326+
+ textindexer.searchable("text")
327+
text = RichText(...)
328+
```
329+
330+
- In the GenericSetup xml of your content type, use the new behavior:
331+
332+
```diff
333+
<property name="behaviors" purge="false">
334+
- <element value="collective.dexteritytextindexer" />
335+
- <element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
336+
+ <element value="plone.textindexer" />
337+
</property>
338+
```
339+
340+
- Search for any left-overs of `collective.dexteritytextindexer` in your code and replace it.
341+
342+
The inline upgrade to Plone will replace the two versions of the old behavior with the new one in all content types.
343+
344+
```{seealso}
345+
[plone/Products.CMFPlone issue #2780](https://github.com/plone/Products.CMFPlone/issues/2780)
346+
```
347+
348+
349+
(v60-plone-base-label)=
350+
351+
## `plone.base` package
352+
353+
Within the Plone code base there are circular dependencies.
354+
Package A uses package B and package B uses package A.
355+
Specifically, `Products.CMFPlone` is the main package of Plone where everything comes together.
356+
It depends on a lot of Plone packages.
357+
But these packages often import code from `Products.CMFPlone`.
358+
This is done in such a way that it works, but it creates an unclear situation and makes it hard to debug errors when there is an error in this implicit dependency chain.
359+
360+
The solution in Plone 6.0 was to create a package called `plone.base`.
361+
Some often used code from `Products.CMFPlone` and other packages was moved here.
362+
Backwards compatibility imports were kept in place, so this should not cause any breakage in add-ons.
363+
You *will* get warnings in your logs, unless you have silenced them.
364+
For example when your code has `from Products.CMFPlone.utils import base_hasattr` you will see:
365+
366+
```
367+
DeprecationWarning: base_hasattr is deprecated.
368+
Import from plone.base.utils instead (will be removed in Plone 7)
369+
```
370+
371+
If the add-on only needs to support Plone 6, you can change the code like this:
372+
373+
```diff
374+
- from Products.CMFPlone.utils import base_hasattr
375+
+ from plone.base.utils import base_hasattr
376+
```
377+
378+
If the add-on needs to support both Plone 5 and 6, this works and avoids the warning:
379+
380+
```python
381+
try:
382+
from plone.base.utils import base_hasattr
383+
except ImportError:
384+
# BBB for Plone 5
385+
from Products.CMFPlone.utils import base_hasattr
386+
```
387+
388+
```{seealso}
389+
[plone/Products.CMFPlone issue #3395](https://github.com/plone/Products.CMFPlone/issues/3395)
390+
```
391+
392+
393+
(v60-modern-image-scales-label)=
394+
395+
## Support for modern image scales
396+
397+
In Plone 5.2 these image scales were available, with scale name, width and height:
398+
399+
```
400+
large 768:768
401+
preview 400:400
402+
mini 200:200
403+
humb 128:128
404+
tile 64:64
405+
icon 32:32
406+
listing 16:16
407+
```
408+
409+
Plone 6.0 changes them:
410+
411+
```
412+
huge 1600:65536
413+
great 1200:65536
414+
larger 1000:65536
415+
large 800:65536
416+
teaser 600:65536
417+
preview 400:65536
418+
mini 200:65536
419+
thumb 128:128
420+
tile 64:64
421+
icon 32:32
422+
listing 16:16
423+
```
424+
425+
- The biggest scale now has a width of 1600 instead of 768.
426+
- The 'large' scale was made slightly bigger: from 768 to 800.
427+
- All scales above 'mini' have a height of 65536.
428+
This does not mean you get an extremely high image.
429+
It means only the width is taken into account when resizing the image.
430+
This is a better fit for most modern themes.
431+
432+
```{note}
433+
The standard Plone upgrade only adds the completely new scales: huge, great, larger, teaser.
434+
It leaves the other scales untouched.
435+
This is to avoid strange differences between old and new images.
436+
For example, old images would otherwise have a large scale with width 768, where for new images this would be width 800.
437+
```
438+
439+
```{seealso}
440+
[plone/Products.CMFPlone issue #3279](https://github.com/plone/Products.CMFPlone/issues/3279)
441+
```
442+
443+
444+
(v60-pre-scaling-label)=
445+
446+
## Image pre scaling
447+
448+
In Plone 6, we have made a split between generating a url for an image scale and actually scaling the image.
449+
Why would you want this?
450+
451+
As an add-on author you create a template and you want to show an uploaded image with the preview scale.
452+
The code would be like this:
453+
454+
```
455+
<img tal:define="images context/@@images"
456+
tal:replace="structure python:images.tag('image', scale='preview')" />
457+
```
458+
459+
In Plone 5 this creates a scale of the image, using the Pillow imaging library.
460+
In Plone 6, the scaled image is not yet created at this point.
461+
The scaled image is only created when (if) the browser actually requests the image.
462+
463+
This is good, because for various reasons, the browser may never actually ask for this scaled image.
464+
For example, the browser may be on a mobile phone with the images turned off to prevent using costly band width.
465+
Also, when the tag contains source sets for HiDPI or picture variants, the browser may see five possible images and only choose to download one of them.
466+
467+
In Plone 6, when generating a tag for in this case the preview scale, a unique url is generated, and information for this scale is pre-registered.
468+
Only when the browser requests the scaled image at this url, does Plone generate the scale.
469+
This avoids generating image scales that never get used.
470+
471+
This performance improvement makes two other image improvements possible.
472+
These follow in the sections directly below.
473+
474+
Add-on authors do not *have* to change anything.
475+
But it is a good idea to check how you are using images, otherwise you miss out on this improvement.
476+
If you call the `tag` method like above, you are good.
477+
If you use the `scale` method and then use its `tag` method, then you should change:
478+
479+
```diff
480+
<img tal:define="images context/@@images"
481+
- tal:replace="structure python:images.scale('image', scale='preview').tag()" />
482+
+ tal:replace="structure python:images.tag('image', scale='preview')" />
483+
```
484+
485+
Alternatively, you can explicitly use the new `pre` argument, but this will fail on Plone 5:
486+
487+
```xml
488+
<img tal:define="images context/@@images"
489+
tal:replace="structure python:images.scale('image', scale='preview', pre=True).tag()" />
490+
```
491+
492+
```{note}
493+
There now is an image test page that shows several scales of an image, in various modes.
494+
In your browser to to an image and add `/@@images-test` to the end of the url.
495+
```
496+
497+
```{seealso}
498+
- [plone/plone.scale PR 57](https://github.com/plone/plone.scale/pull/57)
499+
- [plone/plone.namedfile PR 113](https://github.com/plone/plone.namedfile/pull/113)
500+
```
501+
502+
503+
(v60-responsive-image-support-label)=
504+
505+
## Responsive image support
506+
507+
Responsive image support was added with picture tags.
508+
For more information, see {ref}`classic-ui-images-responsive-image-support`.
509+
510+
In an add-on nothing needs to be changed.
511+
But if you want to use the responsive image support, you should use the `picture` method:
512+
513+
```diff
514+
<img tal:define="images context/@@images"
515+
- tal:replace="structure python:images.tag('image', scale='preview')" />
516+
+ tal:replace="structure python:images.picture('image', picture_variant='small')" />
517+
```
518+
519+
520+
521+
(v60-image-scale-catalog-label)=
522+
523+
## Store image scale info in catalog metadata
524+
525+
When you add or edit an image, Plone 6 pre-registers all scales and stores info about them in the portal catalog.
526+
The catalog brain of an image then has all the needed information about each scale, especially the unique url and the width and height.
527+
This is used on lists of images to be able show a scale in a tag without waking up the image objects from the database.
528+
In other words: this speeds up pages that contain lots of images.
529+
530+
Add-on authors do not have to change anything: this happens automatically.
531+
If you have a very special use case, you can influence this with some new adapters.
532+
533+
```{note}
534+
When upgrading your Plone Site to Plone 6.0, the inline migration finds all images in your site.
535+
It then adds the scale information to the catalog.
536+
This may take a long time.
537+
You can disable this with an environment variable:
538+
`export UPDATE_CATALOG_FOR_IMAGE_SCALES=0`
539+
In that case, you are advised to add the `image_scales` column manually to the catalog later.
540+
```
541+
542+
```{seealso}
543+
[plone/plone.app.upgrade PR 292](https://github.com/plone/plone.app.upgrade/pull/292)
544+
```

0 commit comments

Comments
 (0)