Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions src/fields/Checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getSettingsHtml()
]
);
}

public function getContentColumnType(): string
{
return $this->columnType;
Expand All @@ -41,29 +41,38 @@ public function normalizeValue($value, ElementInterface $element = null): string
$view = Craft::$app->getView();
$templateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->checkboxOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

if ($this->isFresh($element)) :
foreach ($options as $key => $option) :
if (!empty($option['default'])) :
$value[] = $option['value'];
endif;
endforeach;
endif;

if (is_array($value)) :
$value = json_encode($value);
endif;

return (is_null($value) ? '' : $value);
}

public function getInputHtml($value, ElementInterface $element = null): string
{
$view = Craft::$app->getView();
Expand All @@ -72,11 +81,20 @@ public function getInputHtml($value, ElementInterface $element = null): string

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->checkboxOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

return Craft::$app->getView()->renderTemplate('craft-dynamic-fields/_includes/forms/checkboxGroup', [
'name' => $this->handle,
'values' => $value,
Expand Down
40 changes: 29 additions & 11 deletions src/fields/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Dropdown extends Field
{

public $dropdownOptions = '';
public $columnType = 'text';

Expand All @@ -31,36 +31,45 @@ public function getSettingsHtml()
]
);
}

public function getContentColumnType(): string
{
return $this->columnType;
}

public function normalizeValue($value, ElementInterface $element = null): string
{
{
$view = Craft::$app->getView();
$templateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->dropdownOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

if ($this->isFresh($element) ) :
foreach ($options as $key => $option) :
if (!empty($option['default'])) :
$value = $option['value'];
endif;
endforeach;
endif;

return (is_null($value) ? '' : $value);
}

public function getInputHtml($value, ElementInterface $element = null): string
{
$view = Craft::$app->getView();
Expand All @@ -69,11 +78,20 @@ public function getInputHtml($value, ElementInterface $element = null): string

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->dropdownOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

return Craft::$app->getView()->renderTemplate('craft-dynamic-fields/_includes/forms/select', [
'name' => $this->handle,
'value' => $value,
Expand Down
46 changes: 32 additions & 14 deletions src/fields/Multiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getSettingsHtml()
]
);
}

public function getContentColumnType(): string
{
return $this->columnType;
Expand All @@ -43,47 +43,65 @@ public function normalizeValue($value, ElementInterface $element = null): string
$view = Craft::$app->getView();
$templateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->multiselectOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

if ($this->isFresh($element)) :
foreach ($options as $key => $option) :
if (!empty($option['default'])) :
$value[] = $option['value'];
endif;
endforeach;
endif;

if (is_array($value)) :
$value = json_encode($value);
endif;

return (is_null($value) ? '' : $value);
}

public function getInputHtml($value, ElementInterface $element = null): string
{
$view = Craft::$app->getView();
$templateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->multiselectOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

return Craft::$app->getView()->renderTemplate('craft-dynamic-fields/_includes/forms/multiselect', [
'name' => $this->handle,
'values' => $value,
'options' => $options,
'size' => ($this->fieldHeight > 0 ? $this->fieldHeight : count($options))
]);
}
}
}
}
40 changes: 29 additions & 11 deletions src/fields/Radiobuttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Radiobuttons extends Field
{

public $radioOptions = '';
public $columnType = 'text';

Expand All @@ -31,36 +31,45 @@ public function getSettingsHtml()
]
);
}

public function getContentColumnType(): string
{
return $this->columnType;
}

public function normalizeValue($value, ElementInterface $element = null): string
{
{
$view = Craft::$app->getView();
$templateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->radioOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

if ($this->isFresh($element) ) :
foreach ($options as $key => $option) :
if (!empty($option['default'])) :
$value = $option['value'];
endif;
endforeach;
endif;

return (is_null($value) ? '' : $value);
}

public function getInputHtml($value, ElementInterface $element = null): string
{
$view = Craft::$app->getView();
Expand All @@ -69,11 +78,20 @@ public function getInputHtml($value, ElementInterface $element = null): string

$variables['element'] = $element;
$variables['this'] = $this;


$siteHandle = Craft::$app->request->get('site', null);
$currentSite = Craft::$app->sites->currentSite;
if ($siteHandle && $siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite(Craft::$app->sites->getSiteByHandle($siteHandle));
}

$options = json_decode('[' . $view->renderString($this->radioOptions, $variables) . ']', true);

$view->setTemplateMode($templateMode);

if ($siteHandle !== $currentSite->handle) {
Craft::$app->sites->setCurrentSite($currentSite);
}

return Craft::$app->getView()->renderTemplate('craft-dynamic-fields/_includes/forms/radioGroup', [
'name' => $this->handle,
'value' => $value,
Expand Down