Skip to content

Commit

Permalink
chore: craft5 support (#16)
Browse files Browse the repository at this point in the history
* chore: setup ci

Signed-off-by: Fred Carlsen <fred@sjelfull.no>

* chore: refactors and improvements

Signed-off-by: Fred Carlsen <fred@sjelfull.no>

* chore: update readme and changelog + version

Signed-off-by: Fred Carlsen <fred@sjelfull.no>

* chore: cleanup

Signed-off-by: Fred Carlsen <fred@sjelfull.no>

---------

Signed-off-by: Fred Carlsen <fred@sjelfull.no>
  • Loading branch information
sjelfull authored May 12, 2024
1 parent 406c32d commit 889bd24
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 76 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @sjelfull
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug Report
about: Report an issue or unexpected behavior
title: ''
labels: bug
assignees: sjelfull

---

**Describe the bug**
A clear and concise description of what the bug is.

**Steps to reproduce**

1.
2.

**Screenshots/Video**

If applicable, add screenshots or videos to help explain your problem.

**Additional info**
- Craft CMS version:
- Craft Commerce version:
- Vipps for Craft Commerce version:
- PHP version:
- Database driver & version:
- Plugins & versions:
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Feature Request
url: https://github.com/sjelfull/craft3-templateselect/discussions/new?category=ideas
about: Start a new discussion about your idea
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea
title: ''
labels: enhancement
assignees: sjelfull

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Additional context**
- Craft version:
- PHP version:
- Database driver & version:
- Plugins & versions:
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ci
on:
workflow_dispatch:
push:
branches:
- develop
- main
pull_request:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: ci
uses: superbigco/.github/.github/workflows/ci.yml@master
with:
craft_version: '4'
jobs: '["ecs", "phpstan"]'
notify_slack: true
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_CRAFT_PLUGINS_WEBHOOK_URL }}
21 changes: 21 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Create Release
run-name: Create release for ${{ github.event.client_payload.version }}

on:
repository_dispatch:
types:
- craftcms/new-release

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: ncipollo/release-action@v1
with:
body: ${{ github.event.client_payload.notes }}
makeLatest: ${{ github.event.client_payload.latest }}
name: ${{ github.event.client_payload.version }}
prerelease: ${{ github.event.client_payload.prerelease }}
tag: ${{ github.event.client_payload.tag }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 5.0.0 - 2022-10-03
### Added
- Made plugin compatible with Craft 5
- Added support for environment variables in settings
- Added `field.subfolder()` method to get subfolder from the field instance
- Added `field.withSubfolder()` method to get template path including subfolder if set
- Added `field.filename()` method to get the template filename without path

## 3.0.0 - 2022-10-03
### Added
- Made plugin compatible with Craft 4
Expand Down
55 changes: 47 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Template Select plugin for Craft CMS 3.x
# Template Select plugin for Craft CMS

A fieldtype that allows you to select a template from the site templates folder.

![Screenshot](resources/img/field-screenshot@2x.png)
![Screenshot](resources/img/field-with-friendly.png)

## Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.
This plugin requires Craft CMS 4.0 or later.

## Installation

Expand All @@ -24,18 +24,57 @@ To install the plugin, follow these instructions.

## Configuring Template Select

You may limit the template list to a subfolder of the site template folder.
Create a new field and choose field type Template Select.

The path is relative, i.e. _subfolder/subfolder2/_.
In the field settings, you can limit the list of available templates to a subfolder of the Craft templates folder. The path is relative, i.e. _subfolder/anotherfolder_. This may also be set to an ENV variable.

![Subfolder](resources/img/field-config@2x.png)
![Screenshot](resources/img/field-settings.png)

## Using Template Select
![Screenshot](resources/img/field-without-friendly.png)

If you want to include a template, you may do it like this in your entry template:
In the field settings, you can choose to make the template names more user friendly. In the field, the list will be improved by changing the following:
- file extensions will be removed
- the file names will be capitalized and spaced for readability
- folders will be separated by ›

![Screenshot](resources/img/field-with-friendly.png)

## Using Template Selector

### Output the chosen template name:

```twig
{{ entry.fieldHandle }}
```

### Include/Embed the chosen template:

```twig
{% include entry.fieldHandle %}
```

### Include the template including subfolder if set:

```twig
{% include entry.fieldHandle.withSubfolder() %}
```

This is a alias for the following:

```twig
{{ entry.templateWithSubfolder.template(true) }}
```

### Output the subfolder name:

```twig
{{ entry.fieldHandle.subfolder() }}
```

### Output the filename without path:

```twig
{{ entry.fieldHandle.filename() }}
```

Brought to you by [Superbig](https://superbig.co)
14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "superbig/craft3-templateselect",
"description": "A fieldtype that allows you to select a template from a dropdown.",
"type": "craft-plugin",
"version": "3.0.0",
"version": "5.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -24,6 +24,11 @@
"require": {
"craftcms/cms": "^4.0.0"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main"
},
"repositories": [
{
"type": "composer",
Expand All @@ -43,5 +48,12 @@
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/sjelfull/craft3-templateselect/master/CHANGELOG.md",
"class": "superbig\\templateselect\\TemplateSelect"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon
parameters:
level: 5
paths:
- src
Binary file added resources/img/field-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/field-with-friendly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/field-without-friendly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 4 additions & 20 deletions src/TemplateSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@

namespace superbig\templateselect;


use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\services\Fields;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;

use superbig\templateselect\fields\TemplateSelectField;
use yii\base\Event;
Expand All @@ -31,29 +28,20 @@
*/
class TemplateSelect extends Plugin
{
// Static Properties
// =========================================================================

/**
* @var TemplateSelect
*/
public static $plugin;

// Public Methods
// =========================================================================
public static TemplateSelect $plugin;

/**
* @inheritdoc
*/
public function init ()
public function init()
{
parent::init();
self::$plugin = $this;

Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
function (RegisterComponentTypesEvent $event) {
function(RegisterComponentTypesEvent $event) {
$event->types[] = TemplateSelectField::class;
}
);
Expand All @@ -67,8 +55,4 @@ function (RegisterComponentTypesEvent $event) {
__METHOD__
);
}

// Protected Methods
// =========================================================================

}
Loading

0 comments on commit 889bd24

Please sign in to comment.