Source of file CMSFieldUtils.php
Size: 1,878 Bytes - Last Modified: 2021-12-24T06:42:58+00:00
/var/www/docs.ssmods.com/process/src/src/utils/CMSFieldUtils.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php namespace Conan\DataObjectUtils; use SilverStripe\Forms\FormField; class CMSFieldUtils { /** * @param FormField $field * @param string $title * @param string|null $callerClass */ public static function setTitle(FormField $field, string $title, string $callerClass = null): void { $title = $title ?? $field->Title(); $field->setTitle(self::getTranslatedFormFieldString($field, FormFieldConstants::TITLE, $title, $callerClass)); } /** * @param FormField $field * @param string $description * @param string|null $callerClass */ public static function setDescription(FormField $field, string $description, string $callerClass = null): void { $description = $description ?? $field->getDescription(); $field->setDescription(self::getTranslatedFormFieldString($field, FormFieldConstants::DESCRIPTION, $description, $callerClass)); } /** * @param FormField $field * @param string $title * @param string $description * @param string|null $callerClass */ public static function setTitleAndDescription(FormField $field, string $title, string $description, string $callerClass = null): void { self::setTitle($field, $title, $callerClass); self::setDescription($field, $description, $callerClass); } /** * @param FormField $field * @param string $attribute * @param string $string * @param string $callerClass * @return string */ protected static function getTranslatedFormFieldString(FormField $field, string $attribute, string $string, string $callerClass = null): string { $callerClass = $callerClass ?? debug_backtrace()[2]['class']; $i18nEntity = $callerClass . '.' . $field->getName() . '.' . $attribute; return _t($i18nEntity, $string); } } |