Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Apr 6, 2019
1 parent a768405 commit ef111f6
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
.DS_Store
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Read-only Field Changelog

## 1.0.0 - 2019-04-06
### Added
- Initial release
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Read-only Field for Craft CMS 3.x

![Icon](resources/readonly.png)

A very simple read-only field type.

## Background

Sometimes you add content to Craft entries (for example via an API) that should be readable but not changeable for the user in the control panel.

## Requirements

* Craft CMS >= 3.0.0

## Installation

Open your terminal and go to your Craft project:

``` shell
cd /path/to/project
composer require codemonauts/craft-readonly-field
```

In the control panel, go to Settings → Plugins and click the “install” button for *Read-only Field*.

## Usage

After installation, the control panel can be used to create fields that behave like plaintext fields, but can only be filled programmatically with content. In the control panel, the content is displayed but cannot be edited.

With ❤ by [codemonauts](https://codemonauts.com)
35 changes: 18 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{
"name": "codemonauts/craft-readonly-field",
"description": "Craft 3 read-only plaintext field",
"description": "Craft CMS plugin to add a simple, read-only plaintext field.",
"version": "1.0.0",
"type": "craft-plugin",
"minimum-stability": "dev",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin"
"craft-plugin",
"field",
"read-only"
],
"license": "MIT",
"authors": [
{
"name": "codemonauts",
"homepage": "https://codemonauts.com"
}
],
"support": {
"source": "https://github.com/codemonauts/craft-readonly-field",
"docs": "https://github.com/codemonauts/craft-readonly-field/blob/master/README.md",
"issues": "https://github.com/codemonauts/craft-readonly-field/issues"
},
"license": "MIT",
"require": {
"craftcms/cms": "^3.0.0"
},
"autoload": {
"psr-4": {
"codemonauts\\readonly\\": "src/"
}
},
"authors": [
{
"name": "Codemonauts",
"homepage": "https://www.codemonauts.com"
}
],
"require": {
"craftcms/cms": "^3.0.0"
},
"extra": {
"handle": "readonly",
"class": "codemonauts\\readonly\\Readonly",
"name": "Read-only Field",
"developer": "Codemonauts",
"developerUrl": "https://www.codemonauts.com",
"description": "Simple, read-only plaintext field.",
"hasCpSection": false,
"hasSettings": false,
"class": "codemonauts\\readonly\\Readonly"
"hasSettings": false
}
}
Binary file added resources/readonly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Readonly.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace codemonauts\readonly;

use \craft\base\Plugin;
Expand Down
17 changes: 7 additions & 10 deletions src/fields/Readonly.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace codemonauts\readonly\fields;

use Craft;
Expand All @@ -10,8 +11,10 @@

class Readonly extends Field implements PreviewableFieldInterface
{
// Static
// =========================================================================
/**
* @var string The type of database column the field should have in the content table
*/
public $columnType = Schema::TYPE_STRING;

/**
* @inheritdoc
Expand All @@ -21,14 +24,6 @@ public static function displayName(): string
return Craft::t('readonly', 'Read-only Field');
}

/**
* @var string The type of database column the field should have in the content table
*/
public $columnType = Schema::TYPE_STRING;

// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -66,6 +61,7 @@ public function serializeValue($value, ElementInterface $element = null)
if ($value !== null) {
$value = LitEmoji::unicodeToShortcode($value);
}

return $value;
}

Expand All @@ -76,6 +72,7 @@ public function getSearchKeywords($value, ElementInterface $element): string
{
$value = (string)$value;
$value = LitEmoji::unicodeToShortcode($value);

return $value;
}
}
3 changes: 2 additions & 1 deletion src/templates/input.twig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<strong>{{ value }}</strong><input name="{{ name }}" type="hidden" value="{{ value }}" />
<strong>{{ value }}</strong>
<input name="{{ name }}" type="hidden" value="{{ value }}" />

0 comments on commit ef111f6

Please sign in to comment.