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

Fixed numeric aliases 404 handling #1508

Merged
merged 1 commit into from
Jun 13, 2018
Merged

Fixed numeric aliases 404 handling #1508

merged 1 commit into from
Jun 13, 2018

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Apr 30, 2018

When you don't have an url suffix configured or it does not start by a ., the current regex does not match and thus the 404 page is not shown but instead the content of the page is loaded.

Steps to reproduce:

  1. Configure urlSuffix to be an empty string ''.
  2. Add some regular content page with the alias foobar and note your id (e.g. 42).
  3. Call /42.

Expected:

I expect to be redirected to the configured 404 page because the page id 42 has a configured alias foobar.

What happens:

I can see the content of page ID 42.

@leofeyer leofeyer added the bug label Apr 30, 2018
@leofeyer leofeyer added this to the 4.4.19 milestone Apr 30, 2018
@leofeyer leofeyer merged commit 528e360 into contao:4.4 Jun 13, 2018
@leofeyer
Copy link
Member

Thank you @Toflar.

@Toflar Toflar deleted the fix-numeric-alias-with-non-dot-suffix branch June 13, 2018 09:29
@leofeyer leofeyer modified the milestones: 4.4.19, 4.4 May 14, 2019
leofeyer pushed a commit that referenced this pull request Jul 20, 2020
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | #1508 
| Docs PR or issue | contao/docs#468

*Updated description (20/07/08)*

---

### What's inside
This PR ships…
* &hellip; a Twig template + some helper functions (macros) to render a `Image\Studio\Figure` as a `<figure>` tag. This includes a picture + caption and is comparable to the `image.html5` template.
* &hellip; a Twig function to directly render figures from within templates. The function accepts an optional custom template and a set of options that used to configure the `FigureBuilder`.
* &hellip; as a bonus (idea &copy; by @ausi 🙂 ) a function to create `PictureConfiguration`s from within templates. This enables building figures with custom size configurations per template.

#### It enables the following scenarios:
1) Rendering the default template (from a Controller):
```php
$figure = $studio->createFigureBuilder->from($uuid)->setSize(5)->build();

$twig->render('@ContaoCore/Image/Studio/figure.html.twig', ['figure' => $figure]);
```

2) Rendering a custom template with a figure (using the 'figure' macro):
```php
$twig->render('my_template.html.twig', [
  'headline' => $headline,
  'my_figure' => $figure,
]);
```
```twig
{% import "@ContaoCore/Image/Studio/_macros.html.twig" as studio %}

<h1>{{ headline }}</h1>
<div class="container">
  {{ studio.figure(my_figure) }}
</div>
```

3) Rendering a figure from within a template 🌟  (&rarr; uses the default figure template):
```twig
{{ contao_figure(uuid, [200, 200, 'crop'], {
    enableLightBox: true,
    lightBoxGroupIdentifier: 'foo',
}) }}
```

4) Rendering a figure from within a template using a custom figure template:
```html
{{ contao_figure('path/to/an/image.png', '_mySize', {
    disableMetaData,
}, '@app\my_custom_template.html.twig') }}
```

5) Building a picture configuration on the fly (syntax equals definition from config):
```twig
{% set special_config = picture_config({
    width: 400,
    height: 400,
    resize_mode: 'crop',
    sizes: '0.75,1,1.5,2',
    items: [{
        width: 200,
        height: 100,
        media: '(max-width: 140px)',
    }]
}) %}

{{ contao_figure(id, special_config) }}
```

6) Building a figure template from building blocks:
```twig
{% import "@ContaoCore/Image/Studio/_macros.html.twig" as studio %}

<h3>Now look</h3>
<figure class="my_custom_stuff">
  <div class="caption-container">
    {{ studio.caption(figure) }}
  </div>
  {{ studio.picture(figure) }}
</div>
```

7) Overwriting options inside the template:
```twig
{% import "@ContaoCore/Image/Studio/_macros.html.twig" as studio %}

{{ studio.figure(uuid, {}, { 
    attr: { class: 'image-container' },
    caption_attr: { class: 'caption', data-foo: 'bar' }
} }}
```
This principle is borrowed from `symfony/form`. You can define options when creating a `Figure` but you can also specify them when building the template (overwriting the set ones). This makes the whole thing very flexible. Currently you can only define HTML attributes for the various tags but this can easily be extended by either the core or devs creating their own templates. Have a look in the macro file for a more detailed explanation how it is set up.

### Dependencies
Note: This PR is currently based on #1753. The relevant changes are in the following folders:
* `core-bundle\src\Twig\*`
* `core-bundle\views\Image\*`
* `core-bundle\Resources\config\services.yml`
* `core-bundle\tests\Twig\*`

(Commits starting from e76bf63295b6f5d2ff09fc17e74e463139bbb4ab)

### Todo
* [x] Finish templates
* [x] Tests
* [x] Rebase once #1753 is merged

Commits
-------

1877c6a5 add figure Twig template + helper macros
f401a4ec add 'contao_figure' + 'picture_configuration' Twig functions
637c960e add microtags
7dfa1dbf improve naming
124cfe91 add tests
b4497a05 allow dynamic property access for creating picture configurations (+ throw for unmapped keys)
164ba8ed reuse property accessor
65ffc143 allow overwriting meta data on the fly
c287ab88 shorten 'picture_configuration' Twig function to 'picture_config'
7b5ea547 make 'size' an integral part of the 'render_figure' signature

see contao/contao#1937 (comment)
03dfc35c Fix the coding style
a70beef2 expect exceptions late
2f2bfcf9 remove backticks from twig comments
935bbb8f widen type to accept null
39d62485 use FQCN as service names
74310e3e improve property type hint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants