# TYPO3 Extension 'stratis_common'

Stratis Common provides features that can be useful across multiple sites

## Requirements

- TYPO3 9.x
- stratis_site

## Installation

1) Install via composer
2) Enable in extension manager
3) Add static in root template
3) Flush TYPO3 and PHP Caches

#### Flux limit sections feature usage:
- Add `<flux:field.userFunc userFunc="Stratis\\Common\\UserFunction\\DataAttribute->renderField" arguments="{maxitems: '6'}" name="sectionsLimit"/>`<br>
just above the `flux:form.section` which items you is going to limit;
- Set the correct number of `maxitems` argument;

#### Ignore errors on missing images:
`$GLOBALS['TYPO3_CONF_VARS']['DDEV']['DISABLE_IMG_ERRORS'] = 1;`

#### Phone fields validation in BE
If there is needed some custom phone fields validation in BE you need to override next
configuration in `cst_stratis_common.typoscript` (examples placed near constants definition):
```
    phoneField {
        placeholder = __________
        validationPattern = ^\d{10}$
        inputPattern = ^\d{0,10}}$
    }
```

#### Custom page content when user access forbidden

This feature allows you to set custom page to be shown if user will not have access to current page.

**How to activate this feature in old projects:**
- update `stratis_common` to `v1.24.0`
- update site configurations (e.g `config.yaml`)
- fill up `access_forbidden_page` fields for needed pages in BE

**Site configuration example:**
```yaml
# ...
errorHandling:
  # ...
  -
    errorCode: '403'
    errorHandler: PHP
    errorContentSource: '4'
    errorPhpClassFQCN: 'Stratis\Common\ErrorHandler\AccessForbiddenErrorHandler'
```
#### Adding a template when generating exceptions on the site

This function allows you to add a custom template to throw exceptions.

**How to activate this feature in old projects:**
- update `stratis_common` to `v1.25.2`
- add site configurations (e.g `config.yaml`)
```yaml
    errorCode: '500'
    errorHandler: Fluid
    errorFluidTemplate: 'EXT:stratis_site/Resources/Private/Templates/Sites/Error.html'

    errorCode: '503'
    errorHandler: Fluid
    errorFluidTemplate: 'EXT:stratis_site/Resources/Private/Templates/Sites/Error.html'
```
- set `displayErrors = 0` parameter to AdditionalConfiguration

#### Ajax controller

For FE purposes you can configure any you want selection from db, using /ajax endpoint
For that you need to adjust plugin.tx_common_ajax.settings.configs section in typoscript configuration.

Example of configuration:
```typo3_typoscript
plugin.tx_common_ajax {
  settings {
    configs {

      # Test configuration for agenda and news
      agenda {
        table = tx_news_domain_model_news
        select = uid,title
        params {
          0 = deleted = 0 AND hidden = 0
          pid = 132
          order = title ASC

          # Pagination params can be override by GET param, ex: /ajax?config=news&limit=2&offset=5
          offset = 2
          limit = 10
        }
      }

      news {
        table = tx_news_domain_model_news
        select = uid,title
        params {
          0 = deleted = 0 AND hidden = 0
          pid = 107
          order = title ASC
          offset = 5
          limit = 5
        }
      }
    }
  }
}
```

Example of endpoint:
```
http://typo3-9.ddev.site/ajax?config=news&limit=10&offset=10
```

Successful response example:
```json
{
    "success": true,
    "items": [
        {
            "uid": 200,
            "title": "Actualité Pondération contenus"
        },
        {
            "uid": 30,
            "title": "Actualité Pondération titre"
        }
    ]
}
```

Error response example:
```json
{
    "success": false,
    "error": "Error message"
}
```

#### Tarteaucitron

**How to add tarteaucitron 'fancybox' service:**

- Add this HTML code in /typo3conf/ext/stratis_site/Resources/Private/Partials/Page/SharedResources.html file after tarteaucitron.js call and before /stratis_tarteaucitron.js call (between them)

```html
<script src="{f:uri.resource(path: 'JavaScript/Library/Tarteaucitron/stratis.tarteaucitron.services.js', extensionName: 'stratis_common')}"></script>
```

- Enable `fancybox` tarteaucitron service in /typo3conf/ext/stratis_site/Configuration/TypoScript/Constants/cst_stratis_common.typoscript file

```typo3_typoscript
# cat=plugin.ts_stratiscommon//a; type=string; label=Enabled Fancybox
fancybox = 1
```

**How to configure tarteaucitron config file caching:**

To start using new cached route for tarteaucitron config you just need to replace it inclusion in `SharedResources.html` with:
```html
<script src="/typo3temp/assets/js/tarteaucitron.{stratisVar.domainName}.js"></script>
```

If there is no such file in typo3 temp it will be automatically generated and placed by this path with next request.

#### Cache

This allows you to have the frontend cache for additional pages cleared when saving to some page or branch of the page tree.

Commands:

 - `clearCacheCmd = 12,23` - clear the cache for page uid 12 and 23 when saving a record in this page (core)
 - `clearCacheCmd = pages` - clear all frontent page caches of pages (core)
 - `clearCacheCmd = all` - clear ALL caches (core)
 - `clearCacheCmd = cacheTag:pagetag1` - clear cache for all pages tagged with tag `pagetag1` (core)
 - `CType:stratissite_hpactualites` - clear cache for all pages with content element `stratissite_hpactualites`
 - `list_type:news_pi1` - clear cache for all pages with plugin `news_pi1`

Example:
```typo3_typoscript
TCEMAIN {
    clearCacheCmd = CType:stratissite_hpactualites,list_type:news_pi1
}
```
