改进自定义字段支持
This commit is contained in:
@@ -496,20 +496,31 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($item instanceof Typecho_Widget_Helper_Form_Element) {
|
||||
$name = $item->input->getAttribute('name');
|
||||
|
||||
if (preg_match("/^fields\[(.+)\]$/", $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
} else {
|
||||
$item->input->setAttribute('name', 'fields[' . $name . ']');
|
||||
}
|
||||
|
||||
$isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')
|
||||
->trigger($plugged)->isFieldReadOnly($name);
|
||||
if ($plugged && $isFieldReadOnly) {
|
||||
$item->input->setAttribute('readonly', 'readonly');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match("/^fields\[(.+)\]$/", $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
} else {
|
||||
foreach ($item->inputs as $input) {
|
||||
$input->setAttribute('name', 'fields[' . $name . ']');
|
||||
}
|
||||
}
|
||||
|
||||
$item->value($fields->{$name});
|
||||
$defaultFields[$name] = array($item->label, $item->input);
|
||||
|
||||
$elements = $item->container->getItems();
|
||||
array_shift($elements);
|
||||
$div = new Typecho_Widget_Helper_Layout('div');
|
||||
|
||||
foreach ($elements as $el) {
|
||||
$div->addItem($el);
|
||||
}
|
||||
|
||||
$defaultFields[$name] = array($item->label, $div);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,6 +543,13 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
->where('cid = ?', $this->cid));
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')
|
||||
->trigger($plugged)->isFieldReadOnly($row['name']);
|
||||
|
||||
if ($plugged && $isFieldReadOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($defaultFields[$row['name']])) {
|
||||
$fields[] = $row;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user