Skip to content

Commit

Permalink
add support for Feed Me Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Sep 14, 2019
1 parent ef111f6 commit c8d71a5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Read-only Field Changelog

## 1.0.1 - 2019-09-14
### Added
- Support for Feed-Me plugin

## 1.0.0 - 2019-04-06
### Added
- Initial release
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codemonauts/craft-readonly-field",
"description": "Craft CMS plugin to add a simple, read-only plaintext field.",
"version": "1.0.0",
"version": "1.0.1",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down
13 changes: 12 additions & 1 deletion src/Readonly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace codemonauts\readonly;

use \craft\base\Plugin;
use craft\base\Plugin;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
use yii\base\Event;
use codemonauts\readonly\fields\Readonly as ReadonlyField;
use codemonauts\readonly\feedme\Readonly as ReadonlyFeedme;
use craft\feedme\events\RegisterFeedMeFieldsEvent;
use craft\feedme\services\Fields as FeedMeFields;

class Readonly extends Plugin
{
Expand All @@ -17,5 +20,13 @@ public function init()
Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) {
$event->types[] = ReadonlyField::class;
});

// Register field for feed-me plugin if installed
if (\Craft::$app->plugins->isPluginEnabled('feed-me')) {
Event::on(FeedMeFields::class, FeedMeFields::EVENT_REGISTER_FEED_ME_FIELDS, function(RegisterFeedMeFieldsEvent $e) {
$e->fields[] = ReadonlyFeedme::class;
}
);
}
}
}
22 changes: 22 additions & 0 deletions src/feedme/Readonly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace codemonauts\readonly\feedme;

use craft\feedme\base\Field;
use craft\feedme\base\FieldInterface;

class Readonly extends Field implements FieldInterface
{
public static $name = 'Read-only Field';
public static $class = 'codemonauts\readonly\fields\Readonly';

public function getMappingTemplate(): string
{
return 'readonly/feedme';
}

public function parseField(): string
{
return (string)$this->fetchValue();
}
}
18 changes: 18 additions & 0 deletions src/templates/feedme.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{# ------------------------ #}
{# Available Variables #}
{# ------------------------ #}
{# Attributes: #}
{# type, name, handle, instructions, attribute, default, feed, feedData #}
{# ------------------------ #}
{# Fields: #}
{# name, handle, instructions, feed, feedData, field, fieldClass #}
{# ------------------------ #}

{% import 'feed-me/_macros' as feedMeMacro %}
{% import '_includes/forms' as forms %}

{% set default = default ?? {
type: 'text',
} %}

{% extends 'feed-me/_includes/fields/_base' %}

0 comments on commit c8d71a5

Please sign in to comment.