Skip to content

Commit

Permalink
comments cleanup, fixed version number
Browse files Browse the repository at this point in the history
  • Loading branch information
ammannbe committed Jul 22, 2022
1 parent 105c2ba commit 9f24c27
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 173 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ to [Semantic Versioning](http://semver.org/).

- Craft CMS 4 ready
- Comments cleanup
- fixed version number

## 0.0.3 - 2022-06-10

Expand Down
16 changes: 4 additions & 12 deletions src/HOMMIcons.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@
use yii\base\Event;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
* it as simple as we can, but the training wheels are off. A little prior knowledge is
* going to be required to write a plugin.
* Class HOMMIcons
*
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
*
* https://craftcms.com/docs/plugins/introduction
*
* @author Domenik Hofer
* @author Benjamin Ammann
* @package HOMMIcons
* @since 1.0.0
*
* @since 0.0.1
*/
class HOMMIcons extends Plugin
{
Expand All @@ -58,7 +50,7 @@ class HOMMIcons extends Plugin
*
* @var string
*/
public string $schemaVersion = '1.0.0-alpha.1';
public string $schemaVersion = '1.0.0';

/**
* @var bool
Expand Down
18 changes: 3 additions & 15 deletions src/assetbundles/hommicons/HOMMIconsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,15 @@

namespace homm\hommicons\assetbundles\hommicons;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

/**
* HOMMIconsAsset AssetBundle
* Class HOMMIconsAsset
*
* AssetBundle represents a collection of asset files, such as CSS, JS, images.
*
* Each asset bundle has a unique name that globally identifies it among all asset bundles used in an application.
* The name is the [fully qualified class name](http://php.net/manual/en/language.namespaces.rules.php)
* of the class representing it.
*
* An asset bundle can depend on other asset bundles. When registering an asset bundle
* with a view, all its dependent asset bundles will be automatically registered.
*
* http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
*
* @author Domenik Hofer
* @author Benjamin Ammann
* @package HOMMIcons
* @since 1.0.0
* @since 0.0.1
*/
class HOMMIconsAsset extends AssetBundle
{
Expand Down
6 changes: 3 additions & 3 deletions src/assetbundles/hommicons/dist/css/HOMMIconsField.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*
* HOMMIconsField Field CSS
*
* @author Domenik Hofer
* @copyright Copyright (c) 2019 Domenik Hofer
* @author Benjamin Ammann
* @copyright Copyright (c) 2021 Benjamin Ammann
* @link https://github.com/HOMMinteractive
* @package HOMMIcons
* @since 1.0.0
* @since 0.0.1
*/

.homm-iconpicker {
Expand Down
8 changes: 4 additions & 4 deletions src/assetbundles/hommicons/dist/js/HOMMIconsField.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* HOMM Icons plugin for Craft CMS 3.x
HOMM Icons plugin for Craft CMS 3.x
*
* HOMMIconsField Field JS
*
* @author Domenik Hofer
* @copyright Copyright (c) 2019 Domenik Hofer
* @author Benjamin Ammann
* @copyright Copyright (c) 2021 Benjamin Ammann
* @link https://github.com/HOMMinteractive
* @package HOMMIcons
* @since 1.0.0
* @since 0.0.1
*/

;(function ($, window, document, undefined) {
Expand Down
134 changes: 9 additions & 125 deletions src/fields/HOMMIconsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@
use craft\helpers\Json;

/**
* HOMMIconsField Field
* Class HOMMIconsField
*
* Whenever someone creates a new field in Craft, they must specify what
* type of field it is. The system comes with a handful of field types baked in,
* and we’ve made it extremely easy for plugins to add new ones.
*
* https://craftcms.com/docs/plugins/field-types
*
* @author Domenik Hofer
* @author Benjamin Ammann
* @package HOMMIcons
* @since 1.0.0
* @since 0.0.1
*/
class HOMMIconsField extends Field
{
Expand All @@ -52,33 +46,16 @@ public static function displayName(): string
// =========================================================================

/**
* Returns the column type that this field should get within the content table.
*
* This method will only be called if [[hasContentColumn()]] returns true.
*
* @return string The column type. [[\yii\db\QueryBuilder::getColumnType()]] will be called
* to convert the give column type to the physical one. For example, `string` will be converted
* as `varchar(255)` and `string(100)` becomes `varchar(100)`. `not null` will automatically be
* appended as well.
* @see \yii\db\QueryBuilder::getColumnType()
* @inheritdoc
*/
public function getContentColumnType(): array|string
{
return Schema::TYPE_STRING;
}


/**
* Normalizes the field’s value for use.
*
* This method is called when the field’s value is first accessed from the element. For example, the first time
* `entry.myFieldHandle` is called from a template, or right before [[getInputHtml()]] is called. Whatever
* this method returns is what `entry.myFieldHandle` will likewise return, and what [[getInputHtml()]]’s and
* [[serializeValue()]]’s $value arguments will be set to.
*
* @param mixed $value The raw field value
* @param ElementInterface|null $element The element the field is associated with, if there is one
*
* @return mixed The prepared field value
* @inheritdoc
*/
public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $element = null): mixed
{
Expand All @@ -94,102 +71,9 @@ public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $elem

}


/**
* Returns the field’s input HTML.
*
* An extremely simple implementation would be to directly return some HTML:
*
* ```php
* return '<textarea name="'.$name.'">'.$value.'</textarea>';
* ```
*
* For more complex inputs, you might prefer to create a template, and render it via
* [[\craft\web\View::renderTemplate()]]. For example, the following code would render a template located at
* craft/plugins/myplugin/templates/_fieldinput.html, passing the $name and $value variables to it:
*
* ```php
* return Craft::$app->getView()->renderTemplate('myplugin/_fieldinput', [
* 'name' => $name,
* 'value' => $value
* ]);
* ```
*
* If you need to tie any JavaScript code to your input, it’s important to know that any `name=` and `id=`
* attributes within the returned HTML will probably get [[\craft\web\View::namespaceInputs() namespaced]],
* however your JavaScript code will be left untouched.
*
* For example, if getInputHtml() returns the following HTML:
*
* ```html
* <textarea id="foo" name="foo"></textarea>
*
* <script type="text/javascript">
* var textarea = document.getElementById('foo');
* </script>
* ```
*
* …then it might actually look like this before getting output to the browser:
*
* ```html
* <textarea id="namespace-foo" name="namespace[foo]"></textarea>
*
* <script type="text/javascript">
* var textarea = document.getElementById('foo');
* </script>
* ```
*
* As you can see, that JavaScript code will not be able to find the textarea, because the textarea’s `id=`
* attribute was changed from `foo` to `namespace-foo`.
*
* Before you start adding `namespace-` to the beginning of your element ID selectors, keep in mind that the actual
* namespace is going to change depending on the context. Often they are randomly generated. So it’s not quite
* that simple.
*
* Thankfully, [[\craft\web\View]] provides a couple handy methods that can help you deal with this:
*
* - [[\craft\web\View::namespaceInputId()]] will give you the namespaced version of a given ID.
* - [[\craft\web\View::namespaceInputName()]] will give you the namespaced version of a given input name.
* - [[\craft\web\View::formatInputId()]] will format an input name to look more like an ID attribute value.
*
* So here’s what a getInputHtml() method that includes field-targeting JavaScript code might look like:
*
* ```php
* public function getInputHtml($value, $element)
* {
* // Come up with an ID value based on $name
* $id = Craft::$app->getView()->formatInputId($name);
*
* // Figure out what that ID is going to be namespaced into
* $namespacedId = Craft::$app->getView()->namespaceInputId($id);
*
* // Render and return the input template
* return Craft::$app->getView()->renderTemplate('myplugin/_fieldinput', [
* 'name' => $name,
* 'id' => $id,
* 'namespacedId' => $namespacedId,
* 'value' => $value
* ]);
* }
* ```
*
* And the _fieldinput.html template might look like this:
*
* ```twig
* <textarea id="{{ id }}" name="{{ name }}">{{ value }}</textarea>
*
* <script type="text/javascript">
* var textarea = document.getElementById('{{ namespacedId }}');
* </script>
* ```
*
* The same principles also apply if you’re including your JavaScript code with
* [[\craft\web\View::registerJs()]].
*
* @param mixed $value The field’s value. This will either be the [[normalizeValue() normalized value]],
* raw POST data (i.e. if there was a validation error), or null
* @param ElementInterface|null $element The element the field is associated with, if there is one
*
* @return string The input HTML.
* @inheritdoc
*/
public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $element = null): string
{
Expand Down Expand Up @@ -225,7 +109,7 @@ public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $elemen
}

/**
* Get the Icons of the volume "bilder"
* Get the Icons of the volume provided by the settings
*
* @return array the query results. If the query results in nothing, an empty array will be returned.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
use craft\base\Model;

/**
* Class Settings
*
* @author Benjamin Ammann
* @package HOMMSocialFeed
* @package HOMMIcons
* @since 0.0.1
*/
class Settings extends Model
Expand All @@ -25,7 +27,7 @@ class Settings extends Model
/**
* @var string Icon picker base volume name
*/
public $iconsVolume = 'pictures';
public string $iconsVolume = 'pictures';

// Public Methods
// =========================================================================
Expand Down
8 changes: 4 additions & 4 deletions src/templates/_components/fields/HOMMIconsField_input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
* HOMMIconsField Field Input
*
* @author Domenik Hofer
* @copyright Copyright (c) 2019 Domenik Hofer
* @author Benjamin Ammann
* @copyright Copyright (c) 2021 Benjamin Ammann
* @link https://github.com/HOMMinteractive
* @package HOMMIcons
* @since 1.0.0
* @package HOMMSocialFeed
* @since 0.0.1
*/
#}

Expand Down
10 changes: 5 additions & 5 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* HOMM Icons plugin for Craft CMS 3.x
*
* HOMMIconsField Field Input
* HOMMIcons settings
*
* @author Domenik Hofer
* @copyright Copyright (c) 2019 Domenik Hofer
* @author Benjamin Ammann
* @copyright Copyright (c) 2021 Benjamin Ammann
* @link https://github.com/HOMMinteractive
* @package HOMMIcons
* @since 1.0.1
* @package HOMMSocialFeed
* @since 0.0.1
*/
#}

Expand Down
2 changes: 1 addition & 1 deletion src/translations/de/hommicons.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Benjamin Ammann
* @package HOMMIcons
* @since 1.0.1
* @since 0.0.1
*/
return [
'{name} plugin loaded' => '{name} Plugin geladen',
Expand Down
4 changes: 2 additions & 2 deletions src/translations/en/hommicons.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/

/**
* @author Domenik Hofer
* @author Benjamin Ammann
* @package HOMMIcons
* @since 1.0.0
* @since 0.0.1
*/
return [
'{name} plugin loaded' => '{name} plugin loaded',
Expand Down

0 comments on commit 9f24c27

Please sign in to comment.