本文整理汇总了PHP中DropdownField::saveInto方法的典型用法代码示例。如果您正苦于以下问题:PHP DropdownField::saveInto方法的具体用法?PHP DropdownField::saveInto怎么用?PHP DropdownField::saveInto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DropdownField
的用法示例。
在下文中一共展示了DropdownField::saveInto方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveInto
/**
* Save the current value of this field into a DataObject.
* If the field it is saving to is a has_many or many_many relationship,
* it is saved by setByIDList(), otherwise it creates a comma separated
* list for a standard DB text/varchar field.
*
* @param DataObject $record The record to save into
*/
public function saveInto(DataObjectInterface $record)
{
if ($this->multiple) {
$fieldname = $this->name;
$relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
if ($fieldname && $record && $relation && $relation instanceof RelationList) {
$idList = is_array($this->value) ? array_values($this->value) : array();
if (!$record->ID) {
$record->write();
// record needs to have an ID in order to set relationships
$relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
}
$relation->setByIDList($idList);
} elseif ($fieldname && $record) {
if ($this->value) {
$this->value = str_replace(',', '{comma}', $this->value);
$record->{$fieldname} = implode(",", $this->value);
} else {
$record->{$fieldname} = null;
}
}
} else {
parent::saveInto($record);
}
}
示例2: saveInto
/**
* {@inheritdoc}
*/
public function saveInto(DataObjectInterface $record)
{
parent::saveInto($record);
$name = $this->getName();
$record->{$name} = join(',', $this->Value());
$record->write();
}
示例3: saveInto
/**
* {@inheritdoc}
*/
public function saveInto(DataObjectInterface $record)
{
parent::saveInto($record);
$name = $this->getName();
$titleField = $this->getTitleField();
$source = $this->getSource();
$dataClass = $source->dataClass();
$values = $this->Value();
if (!$values) {
$values = array();
}
if (empty($record) || empty($source) || empty($titleField)) {
return;
}
if (!$record->hasMethod($name)) {
throw new Exception(sprintf("%s does not have a %s method", get_class($record), $name));
}
$relation = $record->{$name}();
foreach ($values as $i => $value) {
if (!is_numeric($value)) {
if (!$this->getCanCreate()) {
unset($values[$i]);
continue;
}
$record = new $dataClass();
$record->{$titleField} = $value;
$record->write();
$values[$i] = $record->ID;
}
}
if ($values instanceof SS_List) {
$values = iterator_to_array($values);
}
$relation->setByIDList(array_filter($values));
}
示例4: saveInto
/**
* {@inheritdoc}
*/
public function saveInto(DataObjectInterface $record)
{
parent::saveInto($record);
$name = $this->getName();
$titleField = $this->getTitleField();
$source = $this->getSource();
$values = $this->Value();
$relation = $record->{$name}();
$ids = array();
if (!$values) {
$values = array();
}
if (empty($record) || empty($source) || empty($titleField)) {
return;
}
if (!$record->hasMethod($name)) {
throw new Exception(sprintf("%s does not have a %s method", get_class($record), $name));
}
foreach ($values as $key => $value) {
// Get or create record
$record = $this->getOrCreateTag($value);
if ($record) {
$ids[] = $record->ID;
$values[$key] = $record->Title;
}
}
$relation->setByIDList(array_filter($ids));
}