unionco / core
UNION.co Plugin
Requires
- php: >=8.0
- craftcms/cms: ^4.0
Requires (Dev)
- craftcms/rector: dev-main
- dev-master
- 5.0.0-rc4
- 5.0.0-rc3
- 5.0.0-rc2
- 5.0.0-rc1
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.0
- 3.13.18
- 3.13.17
- 3.13.16
- 3.13.15
- 3.13.14
- 3.13.13
- 3.13.12
- 3.13.11
- 3.13.10
- 3.13.9
- 3.13.8
- 3.13.7
- 3.13.6
- 3.13.5
- 3.13.4
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13
- 3.12.10
- 3.12.9
- 3.12.8
- 3.12.7
- 3.12.6
- 3.12.5
- 3.12.4
- 3.12.3
- 3.12.2
- 3.12.1
- 3.11.0
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.1
- 3.0.0
- 2.3.5
- 2.3.4.1
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3
- 2.2.11
- 2.2.10
- 2.2.8
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4.x-dev
- 2.2.4.1
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 1.2.1
- 1.2
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- dev-feature/craft4
This package is auto-updated.
Last update: 2024-11-16 15:56:10 UTC
README
Welcome to UNION Core for CraftCMS 3.
Although still in beta lots of plugins out there are following suit. UNION Core in CraftCMS 3 will be very different and basically a complete rework but 95% of the functionality still exist.
UNION Core offers a way to attach behaviors to your elements using Craft's own $element->attachBehavior() method. Supplies a global variable that can access your services directly from your templates as well as a few built in behaviors and twig filters for fun.
With CraftCMS 3 and the new way to install plugins we had to come up with way to easily allow you the developer to extend our plugin as before but without needing to dig into the vendor directory. Although possible, we would hate for you to have to do that. Instead, a unionco.php config file will communicate to the plus core code how it will be "extended" on init. More information on this below.
Installation
To install UNION Core, just follow these steps:
- cd into your project's direction
- run
`
composer require unionco\core`
- Go to Settings > Plugins from your Craft control panel and enable the plugin
Config
- Lastly, lets connect it all by creating a unionco.php file in main craft config directory and it should look something like this...
<?php return [ "remotes" => [ "environment-name" => [ 'username' => '', 'host' => '', 'root' => '', 'backupDirectory' => '', 'port' => 22, 'phpPath' => '' ] ] ];
Basic Usage
Out of the box
- AssetBehavior
- Craft Twig Standard Way
`
{{ entry.assetHandle.one.getUrl() }}`
- New Way
`
{{ entry._assetUrl('assetHandle') }}`
- Optional
`
{{ entry._assetUrl('assetHandle', 'squareTransformHandle') }}`
- Eager loaded resources would use
`
{{ entry._eAssetUrl('assetHandle') }}`
- Craft Twig Standard Way
- Video Url Filter
- Currently supports vimeo and youtube urls
- Usage::
`
{{ entry.videoUrl | videoEmbedUrl }}`
- AssetBehavior
Advanced Usage
Behaviors
Behaviors are all bound to the handle of the element.
- Entries: Entry -> Section -> Handle
- Categories: Category -> Group -> Handle
- GlobalSet: Global -> Handle
- Matrixblock: MatrixBlock -> Field -> Handle
Create a file for the element in question (union the word behavior). Example for the Home (single).
<?php namespace union/behaviors/entries use unionco\core\Plugin; //if you need to access the core plugin use unionco\core\behaviors\entries\BaseEntryBehavior; class HomeBehavior extends BaseEntryBehavior { public function _somethingInteresting() { return 'something interesting'; } }
I wont go into tons of detail on how to add behaviors or why we do so, UNIONCore is just the facilitator. Reference the CraftCMS docs or Yii2 docs to get more details about behaviors.
Services
Services will map 1/1 to how services work inside the core plugin and docs for that are already available in the CraftCMS docs github page Docs. The one added benefit of Plus here is the plus variable and its ability to access any of your services from within your templates without needing to create new variables and/or twig extensions. I will give two examples here...
Service will look like this
<?php namespace union\services; use Craft; use craft\base\Component; use unionco\core\Plugin; class QuoteService extends Component { public function getRandomQuote() { // code here } }
Here you have the normal php way of accessing your service:
<?php namespace union/behaviors/entries use unionco\core\Plugin; //if you need to access the core plugin use unionco\core\behaviors\entries\BaseEntryBehavior; class HomeBehavior extends BaseEntryBehavior { public function _somethingInteresting() { $quote = Plugin::$plugin->quote->getRandomQuote(); return $quote; } }
In twig w/UNION Core
{{ union('quote').getRandomQuote() }}