本文整理汇总了PHP中SilverStripe\ORM\DataObject::config方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::config方法的具体用法?PHP DataObject::config怎么用?PHP DataObject::config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SilverStripe\ORM\DataObject
的用法示例。
在下文中一共展示了DataObject::config方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: classForField
/**
* Returns the class name in the class hierarchy which contains a given
* field column for a {@link DataObject}. If the field does not exist, this
* will return null.
*
* @param string $candidateClass
* @param string $fieldName
* @return string
*/
public function classForField($candidateClass, $fieldName)
{
// normalise class name
$candidateClass = ClassInfo::class_name($candidateClass);
if ($candidateClass === 'SilverStripe\\ORM\\DataObject') {
return null;
}
// Short circuit for fixed fields
$fixed = DataObject::config()->fixed_fields;
if (isset($fixed[$fieldName])) {
return $this->baseDataClass($candidateClass);
}
// Find regular field
while ($candidateClass) {
$fields = $this->databaseFields($candidateClass);
if (isset($fields[$fieldName])) {
return $candidateClass;
}
$candidateClass = get_parent_class($candidateClass);
}
return null;
}
示例2: getFieldList
/**
* Gets the form fields as defined through the metadata
* on {@link $obj} and the custom parameters passed to FormScaffolder.
* Depending on those parameters, the fields can be used in ajax-context,
* contain {@link TabSet}s etc.
*
* @return FieldList
*/
public function getFieldList()
{
$fields = new FieldList();
// tabbed or untabbed
if ($this->tabbed) {
$fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
$mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
}
// Add logical fields directly specified in db config
foreach ($this->obj->config()->db as $fieldName => $fieldType) {
// Skip restricted fields
if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) {
continue;
}
// @todo Pass localized title
if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
$fieldClass = $this->fieldClasses[$fieldName];
$fieldObject = new $fieldClass($fieldName);
} else {
$fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
}
// Allow fields to opt-out of scaffolding
if (!$fieldObject) {
continue;
}
$fieldObject->setTitle($this->obj->fieldLabel($fieldName));
if ($this->tabbed) {
$fields->addFieldToTab("Root.Main", $fieldObject);
} else {
$fields->push($fieldObject);
}
}
// add has_one relation fields
if ($this->obj->hasOne()) {
foreach ($this->obj->hasOne() as $relationship => $component) {
if ($this->restrictFields && !in_array($relationship, $this->restrictFields)) {
continue;
}
$fieldName = $component === 'SilverStripe\\ORM\\DataObject' ? $relationship : "{$relationship}ID";
if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
$fieldClass = $this->fieldClasses[$fieldName];
$hasOneField = new $fieldClass($fieldName);
} else {
$hasOneField = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
}
if (empty($hasOneField)) {
continue;
}
// Allow fields to opt out of scaffolding
$hasOneField->setTitle($this->obj->fieldLabel($relationship));
if ($this->tabbed) {
$fields->addFieldToTab("Root.Main", $hasOneField);
} else {
$fields->push($hasOneField);
}
}
}
// only add relational fields if an ID is present
if ($this->obj->ID) {
// add has_many relation fields
if ($this->obj->hasMany() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) {
foreach ($this->obj->hasMany() as $relationship => $component) {
if ($this->tabbed) {
$fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship));
}
$fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'SilverStripe\\Forms\\GridField\\GridField';
/** @var GridField $grid */
$grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create());
if ($this->tabbed) {
$fields->addFieldToTab("Root.{$relationship}", $grid);
} else {
$fields->push($grid);
}
}
}
if ($this->obj->manyMany() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) {
foreach ($this->obj->manyMany() as $relationship => $component) {
if ($this->tabbed) {
$fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship));
}
$fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'SilverStripe\\Forms\\GridField\\GridField';
/** @var GridField $grid */
$grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create());
if ($this->tabbed) {
$fields->addFieldToTab("Root.{$relationship}", $grid);
} else {
$fields->push($grid);
}
}
}
}
return $fields;
//.........这里部分代码省略.........