mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
API Moving placeholder variable to EditableFormField (#581)
This commit is contained in:
parent
a94f0e35aa
commit
457a8a7557
@ -14,6 +14,8 @@ class EditableDateField extends EditableFormField
|
||||
|
||||
private static $plural_name = 'Date Fields';
|
||||
|
||||
private static $has_placeholder = true;
|
||||
|
||||
private static $db = array(
|
||||
'DefaultToToday' => 'Boolean' // From customsettings
|
||||
);
|
||||
|
23
code/model/editableformfields/EditableEmailField.php
Executable file → Normal file
23
code/model/editableformfields/EditableEmailField.php
Executable file → Normal file
@ -14,24 +14,7 @@ class EditableEmailField extends EditableFormField
|
||||
|
||||
private static $plural_name = 'Email Fields';
|
||||
|
||||
private static $db = array(
|
||||
'Placeholder' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
TextField::create(
|
||||
'Placeholder',
|
||||
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
private static $has_placeholder = true;
|
||||
|
||||
public function getSetsOwnError()
|
||||
{
|
||||
@ -59,9 +42,5 @@ class EditableEmailField extends EditableFormField
|
||||
parent::updateFormField($field);
|
||||
|
||||
$field->setAttribute('data-rule-email', true);
|
||||
|
||||
if ($this->Placeholder) {
|
||||
$field->setAttribute('placeholder', $this->Placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,13 @@ class EditableFormField extends DataObject
|
||||
*/
|
||||
public static $allowed_css = array();
|
||||
|
||||
/**
|
||||
* Set this to true to enable placeholder field for any given class
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $has_placeholder = false;
|
||||
|
||||
/**
|
||||
* @config
|
||||
* @var array
|
||||
@ -89,6 +96,7 @@ class EditableFormField extends DataObject
|
||||
"RightTitle" => "Varchar(255)", // from CustomSettings
|
||||
"ShowOnLoad" => "Boolean(1)", // from CustomSettings
|
||||
"ShowInSummary" => "Boolean",
|
||||
"Placeholder" => "Varchar(255)",
|
||||
'DisplayRulesConjunction' => 'Enum("And,Or","Or")',
|
||||
);
|
||||
|
||||
@ -249,6 +257,17 @@ class EditableFormField extends DataObject
|
||||
$fields->addFieldsToTab('Root.DisplayRules', $displayFields);
|
||||
}
|
||||
|
||||
// Placeholder
|
||||
if ($this->config()->has_placeholder) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
TextField::create(
|
||||
'Placeholder',
|
||||
_t('EditableFormField.PLACEHOLDER', 'Placeholder')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
@ -827,6 +846,11 @@ class EditableFormField extends DataObject
|
||||
if ($this->ExtraClass) {
|
||||
$field->addExtraClass($this->ExtraClass);
|
||||
}
|
||||
|
||||
// if this field has a placeholder
|
||||
if ($this->Placeholder) {
|
||||
$field->setAttribute('placeholder', $this->Placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
0
code/model/editableformfields/EditableFormHeading.php
Executable file → Normal file
0
code/model/editableformfields/EditableFormHeading.php
Executable file → Normal file
@ -14,10 +14,11 @@ class EditableNumericField extends EditableFormField
|
||||
|
||||
private static $plural_name = 'Numeric Fields';
|
||||
|
||||
private static $has_placeholder = true;
|
||||
|
||||
private static $db = array(
|
||||
'MinValue' => 'Int',
|
||||
'MaxValue' => 'Int',
|
||||
'Placeholder' => 'Varchar(255)'
|
||||
'MaxValue' => 'Int'
|
||||
);
|
||||
|
||||
public function getSetsOwnError()
|
||||
@ -25,21 +26,6 @@ class EditableNumericField extends EditableFormField
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
TextField::create(
|
||||
'Placeholder',
|
||||
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NumericField
|
||||
*/
|
||||
@ -85,9 +71,5 @@ class EditableNumericField extends EditableFormField
|
||||
if ($this->MaxValue) {
|
||||
$field->setAttribute('data-rule-max', $this->MaxValue);
|
||||
}
|
||||
|
||||
if ($this->Placeholder) {
|
||||
$field->setAttribute('placeholder', $this->Placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
code/model/editableformfields/EditableTextField.php
Executable file → Normal file
15
code/model/editableformfields/EditableTextField.php
Executable file → Normal file
@ -14,6 +14,8 @@ class EditableTextField extends EditableFormField
|
||||
|
||||
private static $plural_name = 'Text Fields';
|
||||
|
||||
private static $has_placeholder = true;
|
||||
|
||||
private static $autocomplete_options = array(
|
||||
'off' => 'Off',
|
||||
'on' => 'On',
|
||||
@ -50,7 +52,6 @@ class EditableTextField extends EditableFormField
|
||||
'MinLength' => 'Int',
|
||||
'MaxLength' => 'Int',
|
||||
'Rows' => 'Int(1)',
|
||||
'Placeholder' => 'Varchar(255)',
|
||||
'Autocomplete' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
@ -72,14 +73,6 @@ class EditableTextField extends EditableFormField
|
||||
))
|
||||
);
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
TextField::create(
|
||||
'Placeholder',
|
||||
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
|
||||
)
|
||||
);
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
DropdownField::create(
|
||||
@ -159,10 +152,6 @@ class EditableTextField extends EditableFormField
|
||||
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
|
||||
}
|
||||
|
||||
if ($this->Placeholder) {
|
||||
$field->setAttribute('placeholder', $this->Placeholder);
|
||||
}
|
||||
|
||||
if ($this->Autocomplete) {
|
||||
$field->setAttribute('autocomplete', $this->Autocomplete);
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ class UserFormsUpgradeService
|
||||
// - MinLength (EditableTextField)
|
||||
// - MaxLength (EditableTextField)
|
||||
// - Rows (EditableTextField)
|
||||
// - Placeholder (EditableTextField / EditableEmailField / EditableNumericField)
|
||||
|
||||
$customSettings = $field->CustomSettings
|
||||
? unserialize($field->CustomSettings)
|
||||
@ -142,6 +143,11 @@ class UserFormsUpgradeService
|
||||
}
|
||||
|
||||
$field->migrateSettings($customSettings);
|
||||
|
||||
if ($field->config()->has_placeholder) {
|
||||
$this->migratePlaceholder($field, $field->ClassName);
|
||||
}
|
||||
|
||||
$field->write();
|
||||
}
|
||||
|
||||
@ -224,4 +230,62 @@ class UserFormsUpgradeService
|
||||
{
|
||||
return $this->quiet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Migrate Placeholder data from field specific table to the EditableFormField table
|
||||
*
|
||||
* @param EditableFormField $field
|
||||
* @param string $tableName
|
||||
*/
|
||||
private function migratePlaceholder($field, $tableName)
|
||||
{
|
||||
// Migrate Placeholder setting from $tableName table to EditableFormField table
|
||||
if ($field->Placeholder) {
|
||||
return;
|
||||
}
|
||||
// Check if draft table exists
|
||||
if (!DB::get_schema()->hasTable($tableName)) {
|
||||
// Check if _obsolete_ draft table exists
|
||||
$tableName = '_obsolete_' . $tableName;
|
||||
if (!DB::get_schema()->hasTable($tableName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check if old Placeholder column exists
|
||||
if (!DB::get_schema()->hasField($tableName, 'Placeholder')) {
|
||||
return;
|
||||
}
|
||||
// Fetch existing draft Placeholder value
|
||||
$query = "SELECT \"Placeholder\" FROM \"$tableName\" WHERE \"ID\" = '$field->ID'";
|
||||
$draftPlaceholder = DB::query($query)->value();
|
||||
|
||||
if (!$draftPlaceholder) {
|
||||
return;
|
||||
}
|
||||
// Update draft Placeholder value
|
||||
DB::prepared_query(
|
||||
"UPDATE \"EditableFormField\" SET \"Placeholder\" = ? WHERE \"ID\" = ?",
|
||||
array($draftPlaceholder, $field->ID)
|
||||
);
|
||||
|
||||
$livePlaceholder = $draftPlaceholder;
|
||||
|
||||
// Check if live table exists
|
||||
$tableName = $tableName . '_Live';
|
||||
if (DB::get_schema()->hasTable($tableName)) {
|
||||
// Fetch existing live Placeholder value
|
||||
$query = "SELECT \"Placeholder\" FROM \"$tableName\" WHERE \"ID\" = '" . $field->ID . "'";
|
||||
$livePlaceholder = DB::query($query)->value();
|
||||
if (!$livePlaceholder) {
|
||||
$livePlaceholder = $draftPlaceholder;
|
||||
}
|
||||
}
|
||||
|
||||
// Update live Placeholder value
|
||||
DB::prepared_query(
|
||||
"UPDATE \"EditableFormField_Live\" SET \"Placeholder\" = ? WHERE \"ID\" = ?",
|
||||
array($draftPlaceholder, $field->ID)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ de_DE:
|
||||
NOTBLANK: 'Nicht leer'
|
||||
NOTVALUE: 'Kein Wert'
|
||||
OPTIONS: Optionen
|
||||
PLACEHOLDER: Platzhalter
|
||||
PLURALNAME: 'Editierbare Formularfelder'
|
||||
REQUIRED: 'Pflichtfeld?'
|
||||
RIGHTTITLE: 'Titel rechts'
|
||||
@ -111,7 +112,6 @@ de_DE:
|
||||
AUTOCOMPLETE: 'Automatisch vervollständigen'
|
||||
AUTOCOMPLETE_DESCRIPTION: 'Unterstützte Browser versuchen, dieses Feld automatisch mit den Benutzerinformationen zu füllen, verwenden, um den gefüllten Wert festzulegen'
|
||||
NUMBERROWS: 'Anzahl der Zeilen'
|
||||
PLACEHOLDER: Platzhalter
|
||||
PLURALNAME: Textfelder
|
||||
SINGULARNAME: Textfeld
|
||||
TEXTLENGTH: Textlänge
|
||||
|
@ -83,6 +83,7 @@ en:
|
||||
NOTBLANK: 'Not Blank'
|
||||
NOTVALUE: 'Not Value'
|
||||
OPTIONS: Options
|
||||
PLACEHOLDER: Placeholder
|
||||
PLURALNAME: 'Editable Form Fields'
|
||||
REQUIRED: 'Is this field Required?'
|
||||
REQUIRED_DESCRIPTION: 'Please note that conditional fields can''t be required'
|
||||
@ -144,7 +145,6 @@ en:
|
||||
AUTOCOMPLETE_DESCRIPTION: 'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated'
|
||||
NUMBERROWS: 'Number of rows'
|
||||
NUMBERROWS_DESCRIPTION: 'Fields with more than one row will be generated as a textarea'
|
||||
PLACEHOLDER: Placeholder
|
||||
PLURALNAME: 'Text Fields'
|
||||
RANGE_TO: to
|
||||
SINGULARNAME: 'Text Field'
|
||||
|
@ -83,6 +83,7 @@ eo:
|
||||
NOTBLANK: 'Ne vaka'
|
||||
NOTVALUE: 'Ne valoro'
|
||||
OPTIONS: Agordoj
|
||||
PLACEHOLDER: Lokokupilo
|
||||
PLURALNAME: 'Redakteblaj formularaj kampoj'
|
||||
REQUIRED: 'Ĉu ĉi tiu kampo estas nepra?'
|
||||
REQUIRED_DESCRIPTION: 'Bonvolu noti ke kondiĉaj kampoj ne povas esti nepraj'
|
||||
@ -142,7 +143,6 @@ eo:
|
||||
EditableTextField:
|
||||
NUMBERROWS: 'Nombro da vicoj'
|
||||
NUMBERROWS_DESCRIPTION: 'Kampoj kun pli ol unu vico generiĝos kiel tekstareo'
|
||||
PLACEHOLDER: Lokokupilo
|
||||
PLURALNAME: 'Tekstaj kampoj'
|
||||
RANGE_TO: al
|
||||
SINGULARNAME: 'Teksta kampo'
|
||||
|
@ -83,6 +83,7 @@ fi_FI:
|
||||
NOTBLANK: 'Ei ole tyhjä'
|
||||
NOTVALUE: 'Ei ole sama kuin'
|
||||
OPTIONS: Valinnat
|
||||
PLACEHOLDER: Opastusteksti
|
||||
PLURALNAME: 'Muokattavat lomakekentät'
|
||||
REQUIRED: 'Onko tämä kenttä pakollinen?'
|
||||
REQUIRED_DESCRIPTION: 'Huomioithan, että ehdolliset kentät eivät voi olla pakollisia'
|
||||
@ -142,7 +143,6 @@ fi_FI:
|
||||
EditableTextField:
|
||||
NUMBERROWS: 'Rivien määrä'
|
||||
NUMBERROWS_DESCRIPTION: 'Kenttät, joissa on enemmän kuin yksi rivi, luodaan tekstialueena.'
|
||||
PLACEHOLDER: Opastusteksti
|
||||
PLURALNAME: Tekstikentät
|
||||
RANGE_TO: –
|
||||
SINGULARNAME: Tekstikenttä
|
||||
|
@ -83,6 +83,7 @@ it:
|
||||
NOTBLANK: 'Non vuoto'
|
||||
NOTVALUE: 'Non valore'
|
||||
OPTIONS: Opzioni
|
||||
PLACEHOLDER: Segnaposto
|
||||
PLURALNAME: 'Campi modulo modificabili'
|
||||
REQUIRED: 'Questo campo è obbligatorio?'
|
||||
REQUIRED_DESCRIPTION: 'Prego nota che i campi condizionali non possono essere obbligatori'
|
||||
@ -144,7 +145,6 @@ it:
|
||||
AUTOCOMPLETE_DESCRIPTION: 'I browser supportati cercheranno di popolare automaticamente questo campo con l'informazione agli utenti, usare per impostare il valore popolata'
|
||||
NUMBERROWS: 'Numero di righe'
|
||||
NUMBERROWS_DESCRIPTION: 'Campi con più di una riga verranno generati come area testo'
|
||||
PLACEHOLDER: Segnaposto
|
||||
PLURALNAME: 'Campi testo'
|
||||
RANGE_TO: a
|
||||
SINGULARNAME: 'Campo testo'
|
||||
|
@ -82,6 +82,7 @@ sk:
|
||||
NOTBLANK: Vyplnené
|
||||
NOTVALUE: 'Nie zadanú hodnotu'
|
||||
OPTIONS: Voľba/možnosť
|
||||
PLACEHOLDER: 'Zástupná/Ukážková hodnota (placeholder)'
|
||||
PLURALNAME: 'Formulárové polia'
|
||||
REQUIRED: 'Je pole povinné/vyžadované?'
|
||||
REQUIRED_DESCRIPTION: 'Všimnite si prosím, že podmienené polia nemôžu byť vyžadované.'
|
||||
@ -138,7 +139,6 @@ sk:
|
||||
EditableTextField:
|
||||
NUMBERROWS: 'Počet riadkov'
|
||||
NUMBERROWS_DESCRIPTION: 'Políčka s viac ako jedným riadkom sú generované ako textarea.'
|
||||
PLACEHOLDER: 'Zástupná/Ukážková hodnota (placeholder)'
|
||||
PLURALNAME: 'Textové polia'
|
||||
RANGE_TO: do
|
||||
SINGULARNAME: 'Textové pole'
|
||||
|
Loading…
Reference in New Issue
Block a user