Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rias committed Jan 4, 2018
2 parents 54d51b2 + 25b5baf commit 9637d1c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
1 change: 0 additions & 1 deletion .craftplugin

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rias/craft3-position-fieldtype",
"description": "Brings back the Position fieldtype from Craft 2",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand All @@ -22,7 +22,7 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-beta.23"
"craftcms/cms": "^3.0.0-RC1"
},
"repositories": [
{
Expand Down
31 changes: 29 additions & 2 deletions src/fields/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@
* @author Rias
* @package PositionFieldtype
* @since 1.0.0
*
* @property string $contentColumnType
* @property null|string $settingsHtml
*/
class Position extends Field
{
// Public Properties
// =========================================================================

/**
* Some attribute
* Available options
*
* @var string
*/
public $options = [];

/**
* Default value
*
* @var string
*/
public $default = '';

// Static Methods
// =========================================================================

Expand Down Expand Up @@ -76,6 +86,7 @@ public function rules()
$rules = parent::rules();
$rules = array_merge($rules, [
['options', 'each', 'rule' => ['string']],
['default', 'string'],
]);
return $rules;
}
Expand Down Expand Up @@ -118,15 +129,28 @@ public function normalizeValue($value, ElementInterface $element = null)
* Returns the component’s settings HTML.
*
* @return string|null
* @throws \Twig_Error_Loader
* @throws \yii\base\Exception
*/
public function getSettingsHtml()
{
// Register our asset bundle
Craft::$app->getView()->registerAssetBundle(PositionFieldTypeAsset::class);

// Get our id and namespace
$id = Craft::$app->getView()->formatInputId($this);
$namespacedId = Craft::$app->getView()->namespaceInputId($id);

Craft::$app->getView()->registerJs("new PositionSelectInput('{$namespacedId}');");

// Render the settings template
return Craft::$app->getView()->renderTemplate(
'position-fieldtype/_components/fields/Position_settings',
[
'field' => $this,
'allOptions' => array_keys(static::getOptions()),
'id' => $id,
'namespacedId' => $namespacedId,
'settings' => $this->settings,
]
);
Expand All @@ -135,12 +159,15 @@ public function getSettingsHtml()
/**
* Returns the field’s input HTML.
*
* @param mixed $value The field’s value.
* @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.
* @throws \Twig_Error_Loader
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function getInputHtml($value, ElementInterface $element = null): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_components/fields/Position_input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="{{ id }}" class="btngroup big">
{% for option, label in allOptions %}
{% if field.options[option] %}
<div title="{{ label }}" class="btn big {% if option == value %} active{% endif %} position-icon-{{ option }}" data-option="{{ option }}"></div>
<div title="{{ label }}" class="btn big {% if value is not null ? option == value : field.default == option %} active{% endif %} position-icon-{{ option }}" data-option="{{ option }}"></div>
{% endif %}
{% endfor %}
</div>
Expand Down
17 changes: 15 additions & 2 deletions src/templates/_components/fields/Position_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

{% import "_includes/forms" as forms %}

{% import "_includes/forms" as forms %}

{% do view.registerAssetBundle("rias\\positionfieldtype\\assetbundles\\positionfieldtype\\PositionFieldtypeAsset") %}

{% set input %}
Expand Down Expand Up @@ -45,3 +43,18 @@
instructions: "Choose which position options should be available to your field."|t('position-fieldtype'),
}, input) }}

<div class="field">
<div class="heading">
<label>{{ "Default" | t('position-fieldtype') }}</label>
<div class="instructions"><p>{{ "Choose a default position" | t('position-fieldtype') }}</p>
</div>
</div>

<div id="{{ id }}" class="btngroup big">
{% for option, label in allOptions %}
<div title="{{ label }}" class="btn big {% if settings.default is not empty and settings.default == label %} active{% endif %} position-icon-{{ label }}" data-option="{{ label }}"></div>
{% endfor %}
</div>

<input type="hidden" name="default" value="{{ settings.default }}">
</div>
4 changes: 3 additions & 1 deletion src/translations/en/position-fieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
'Drop-right' => 'Drop-right',
'Drop-left' => 'Drop-left',
'Choose which position options should be available to your field.' => 'Choose which position options should be available to your field.',
'Full' => 'Full'
'Full' => 'Full',
'Default' => 'Default',
'Choose a default position' => 'Choose a default position',
];
4 changes: 3 additions & 1 deletion src/translations/nl/position-fieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
'Drop-right' => 'Beneden-rechts',
'Drop-left' => 'Beneden-links',
'Choose which position options should be available to your field.' => 'Kies welke positie opties er beschikbaar moeten zijn voor dit veld.',
'Full' => 'Volledig'
'Full' => 'Volledig',
'Default' => 'Standaardwaarde',
'Choose a default position' => 'Kies een standaard positie',
];

0 comments on commit 9637d1c

Please sign in to comment.