Skip to content

Commit ef111f6

Browse files
committed
update documentation
1 parent a768405 commit ef111f6

File tree

8 files changed

+65
-28
lines changed

8 files changed

+65
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
.DS_Store

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Read-only Field Changelog
2+
3+
## 1.0.0 - 2019-04-06
4+
### Added
5+
- Initial release

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Read-only Field for Craft CMS 3.x
2+
3+
![Icon](resources/readonly.png)
4+
5+
A very simple read-only field type.
6+
7+
## Background
8+
9+
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.
10+
11+
## Requirements
12+
13+
* Craft CMS >= 3.0.0
14+
15+
## Installation
16+
17+
Open your terminal and go to your Craft project:
18+
19+
``` shell
20+
cd /path/to/project
21+
composer require codemonauts/craft-readonly-field
22+
```
23+
24+
In the control panel, go to Settings → Plugins and click the “install” button for *Read-only Field*.
25+
26+
## Usage
27+
28+
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.
29+
30+
With ❤ by [codemonauts](https://codemonauts.com)

composer.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
{
22
"name": "codemonauts/craft-readonly-field",
3-
"description": "Craft 3 read-only plaintext field",
3+
"description": "Craft CMS plugin to add a simple, read-only plaintext field.",
44
"version": "1.0.0",
55
"type": "craft-plugin",
6-
"minimum-stability": "dev",
76
"keywords": [
87
"craft",
98
"cms",
109
"craftcms",
11-
"craft-plugin"
10+
"craft-plugin",
11+
"field",
12+
"read-only"
13+
],
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "codemonauts",
18+
"homepage": "https://codemonauts.com"
19+
}
1220
],
1321
"support": {
22+
"source": "https://github.com/codemonauts/craft-readonly-field",
1423
"docs": "https://github.com/codemonauts/craft-readonly-field/blob/master/README.md",
1524
"issues": "https://github.com/codemonauts/craft-readonly-field/issues"
1625
},
17-
"license": "MIT",
26+
"require": {
27+
"craftcms/cms": "^3.0.0"
28+
},
1829
"autoload": {
1930
"psr-4": {
2031
"codemonauts\\readonly\\": "src/"
2132
}
2233
},
23-
"authors": [
24-
{
25-
"name": "Codemonauts",
26-
"homepage": "https://www.codemonauts.com"
27-
}
28-
],
29-
"require": {
30-
"craftcms/cms": "^3.0.0"
31-
},
3234
"extra": {
3335
"handle": "readonly",
36+
"class": "codemonauts\\readonly\\Readonly",
3437
"name": "Read-only Field",
35-
"developer": "Codemonauts",
36-
"developerUrl": "https://www.codemonauts.com",
38+
"description": "Simple, read-only plaintext field.",
3739
"hasCpSection": false,
38-
"hasSettings": false,
39-
"class": "codemonauts\\readonly\\Readonly"
40+
"hasSettings": false
4041
}
4142
}

resources/readonly.png

4.79 KB
Loading

src/Readonly.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace codemonauts\readonly;
34

45
use \craft\base\Plugin;

src/fields/Readonly.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace codemonauts\readonly\fields;
34

45
use Craft;
@@ -10,8 +11,10 @@
1011

1112
class Readonly extends Field implements PreviewableFieldInterface
1213
{
13-
// Static
14-
// =========================================================================
14+
/**
15+
* @var string The type of database column the field should have in the content table
16+
*/
17+
public $columnType = Schema::TYPE_STRING;
1518

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

24-
/**
25-
* @var string The type of database column the field should have in the content table
26-
*/
27-
public $columnType = Schema::TYPE_STRING;
28-
29-
// Public Methods
30-
// =========================================================================
31-
3227
/**
3328
* @inheritdoc
3429
*/
@@ -66,6 +61,7 @@ public function serializeValue($value, ElementInterface $element = null)
6661
if ($value !== null) {
6762
$value = LitEmoji::unicodeToShortcode($value);
6863
}
64+
6965
return $value;
7066
}
7167

@@ -76,6 +72,7 @@ public function getSearchKeywords($value, ElementInterface $element): string
7672
{
7773
$value = (string)$value;
7874
$value = LitEmoji::unicodeToShortcode($value);
75+
7976
return $value;
8077
}
8178
}

src/templates/input.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<strong>{{ value }}</strong><input name="{{ name }}" type="hidden" value="{{ value }}" />
1+
<strong>{{ value }}</strong>
2+
<input name="{{ name }}" type="hidden" value="{{ value }}" />

0 commit comments

Comments
 (0)