Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Получение вариантов значений для ComboBoxWidget из ORM #62

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/widget/ComboBoxWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DigitalWand\AdminHelper\Widget;

use Bitrix\Main\Entity\EnumField;
use Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);
Expand All @@ -13,6 +14,7 @@
* <ul>
* <li> STYLE - inline-стили</li>
* <li> VARIANTS - массив с вариантами значений или функция для их получения в формате ключ=>заголовок
* Не обязателен для EnumField с определенным списком значений (values).
* Например:
* [
* 1=>'Первый пункт',
Expand Down Expand Up @@ -153,7 +155,7 @@ protected function getMultipleValueReadonly()
* '789' => array('ID' => 789, 'TITLE' => 'pish-pish'),
* )
* </code>
*
*
* Результат будет выводиться в комбобоксе.
* @return array
*/
Expand All @@ -170,6 +172,14 @@ protected function getVariants()
}elseif (is_array($variants) AND !empty($variants)) {
return $this->formatVariants($variants);
}
else {
// попытаемся получить список вариантов из описания поля в ORM
$field = ($this->entityName)::getEntity()->getField($this->getCode());
if ($field instanceof EnumField)
{
return $this->formatVariants(array_flip($field->getValues()));
}
}

return array();
}
Expand Down