Skip to content

Commit

Permalink
set default text (if nothing is present)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateiler committed Apr 9, 2019
1 parent f27a558 commit 51b9628
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flipboxfactory/craft-link",
"description": "Link Field Type for Craft CMS",
"version": "1.1.3",
"version": "1.1.2",
"type": "craft-plugin",
"keywords": [
"flipbox",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@
id: 'placeholder',
value: type.settings.placeholder
}) }}
{% endblock %}

{% block notRequiredTextToggle %}
{{ forms.lightswitchField({
label: 'Use Email as default text'|t('link'),
name: 'useEmailAsDefaultText',
id: 'useEmailAsDefaultText',
on: type.settings.useEmailAsDefaultText,
}) }}
{% endblock %}
10 changes: 9 additions & 1 deletion src/templates/_components/fieldtypes/Link/types/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
instructions: 'Require the user defined text field to be populated'|t('link'),
name: 'requireText',
id: 'requireText',
on: type.settings.requireText
on: type.settings.requireText,
toggle: "text-require-text-field",
reverseToggle: "text-not-require-text-field"
}) }}
<div id="text-require-text-field" class="{% if not type.settings.requireText %}hidden{% endif %}">
{% block requiredTextToggle %}{% endblock %}
</div>
<div id="text-not-require-text-field" class="{% if type.settings.requireText %}hidden{% endif %}">
{% block notRequiredTextToggle %}{% endblock %}
</div>
</div>

{{ forms.lightswitchField({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@
id: 'placeholder',
value: type.settings.placeholder
}) }}
{% endblock %}
{% endblock %}

{% block notRequiredTextToggle %}
{{ forms.lightswitchField({
label: 'Use URL as default text'|t('link'),
name: 'useUrlAsDefaultText',
id: 'useUrlAsDefaultText',
on: type.settings.useUrlAsDefaultText,
}) }}
{% endblock %}
22 changes: 20 additions & 2 deletions src/types/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class Email extends AbstractType
const INPUT_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/input';

/**
* @var
* @var bool
*/
public $useEmailAsDefaultText = true;

/**
* @var string
*/
public $email;

Expand All @@ -49,6 +54,18 @@ public static function displayName(): string
return Link::t('Email');
}

/**
* @return string|null
*/
public function getText()
{
if ($this->allowText && $this->overrideText !== null) {
return $this->overrideText;
}

return $this->useEmailAsDefaultText ? $this->email : null;
}

/**
* @return string
*/
Expand All @@ -65,7 +82,8 @@ public function settings(): array
return array_merge(
parent::settings(),
[
'placeholder'
'placeholder',
'useEmailAsDefaultText'
]
);
}
Expand Down
22 changes: 11 additions & 11 deletions src/types/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class Url extends AbstractType
const INPUT_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/input';

/**
* @var
* @var bool
*/
public $useUrlAsDefaultText = true;

/**
* @var string
*/
public $url;

Expand All @@ -54,17 +59,11 @@ public static function displayName(): string
*/
public function getText()
{
if ($this->allowText) {
if ($this->overrideText !== null) {
return $this->overrideText;
}

if (!$this->requireText) {
return null;
}
if ($this->allowText && $this->overrideText !== null) {
return $this->overrideText;
}

return $this->getUrl();
return $this->useUrlAsDefaultText ? $this->getUrl() : null;
}

/**
Expand All @@ -83,7 +82,8 @@ public function settings(): array
return array_merge(
parent::settings(),
[
'placeholder'
'placeholder',
'useUrlAsDefaultText'
]
);
}
Expand Down

0 comments on commit 51b9628

Please sign in to comment.