diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..fb6372b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,16 @@ +The MIT License (MIT) + +Copyright (c) 2018 Codemonauts + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e24a7db --- /dev/null +++ b/composer.json @@ -0,0 +1,41 @@ +{ + "name": "codemonauts/craft-readonly-field", + "description": "Craft 3 read-only plaintext field", + "version": "1.0.0", + "type": "craft-plugin", + "minimum-stability": "dev", + "keywords": [ + "craft", + "cms", + "craftcms", + "craft-plugin" + ], + "support": { + "docs": "https://github.com/codemonauts/craft-readonly-field/blob/master/README.md", + "issues": "https://github.com/codemonauts/craft-readonly-field/issues" + }, + "license": "MIT", + "autoload": { + "psr-4": { + "codemonauts\\readonly\\": "src/" + } + }, + "authors": [ + { + "name": "Codemonauts", + "homepage": "https://www.codemonauts.com" + } + ], + "require": { + "craftcms/cms": "^3.0.0" + }, + "extra": { + "handle": "readonly", + "name": "Read-only Field", + "developer": "Codemonauts", + "developerUrl": "https://www.codemonauts.com", + "hasCpSection": false, + "hasSettings": false, + "class": "codemonauts\\readonly\\Readonly" + } +} diff --git a/src/Readonly.php b/src/Readonly.php new file mode 100644 index 0000000..4b4d92a --- /dev/null +++ b/src/Readonly.php @@ -0,0 +1,20 @@ +types[] = ReadonlyField::class; + }); + } +} diff --git a/src/fields/Readonly.php b/src/fields/Readonly.php new file mode 100644 index 0000000..a8295df --- /dev/null +++ b/src/fields/Readonly.php @@ -0,0 +1,81 @@ +columnType; + } + + /** + * @inheritdoc + */ + public function getInputHtml($value, ElementInterface $element = null): string + { + return Craft::$app->getView()->renderTemplate('readonly/input', + [ + 'name' => $this->handle, + 'value' => $value, + 'field' => $this, + ]); + } + + /** + * @inheritdoc + */ + public function serializeValue($value, ElementInterface $element = null) + { + if ($value !== null) { + $value = LitEmoji::unicodeToShortcode($value); + } + return $value; + } + + /** + * @inheritdoc + */ + public function getSearchKeywords($value, ElementInterface $element): string + { + $value = (string)$value; + $value = LitEmoji::unicodeToShortcode($value); + return $value; + } +} diff --git a/src/templates/input.twig b/src/templates/input.twig new file mode 100644 index 0000000..b9dc125 --- /dev/null +++ b/src/templates/input.twig @@ -0,0 +1 @@ +{{ value }} diff --git a/src/translations/de/readonly.php b/src/translations/de/readonly.php new file mode 100644 index 0000000..ec66f66 --- /dev/null +++ b/src/translations/de/readonly.php @@ -0,0 +1,5 @@ + 'Schreibgeschütztes Feld', +];