Handle display of fields on "edit" term screen.

@return \Closure
340218
protected function outputEditFields()
    {
        return function ($term) {
            /** @var \WP_Term $term */
            foreach ($this->repository as $field) {
                if (method_exists($field, 'termGet')) {
                    $field->termGet($term->term_id);
                }
            }

            echo $this->factory->make('themosis.taxonomy.edit', [
                'fields' => $this->repository
            ])->render();
        };
    }
283058
protected function getFieldsToUpdate()
    {
        $toUpdate = array();

        $fields     = $this->_item->getFields();
        $origFields = $this->_item->getOrigFields();
        foreach ($fields as $field => $value) {
            if (! array_key_exists($field, $origFields) or $value != $origFields[$field]) {
                $toUpdate[$field] = $value;
            }
        }

        return $toUpdate;
    }
986839
function closing() {
    	$lines = array();

    	foreach ($this->edits as $edit) {
    		if ($edit->closing)
    			array_splice($lines, sizeof($lines), 0, $edit->closing);
    	}
    	return $lines;
    }
1111615
private function changedRevisionableFields()
    {
        $changes_to_record = array();
        foreach ($this->dirtyData as $key => $value) {
            // check that the field is revisionable, and double check
            // that it's actually new data in case dirty is, well, clean
            if ($this->isRevisionable($key) && !is_array($value)) {
                if (!isset($this->originalData[$key]) || $this->originalData[$key] != $this->updatedData[$key]) {
                    $changes_to_record[$key] = $value;
                }
            } else {
                // we don't need these any more, and they could
                // contain a lot of data, so lets trash them.
                unset($this->updatedData[$key]);
                unset($this->originalData[$key]);
            }
        }

        return $changes_to_record;
    }
1119962
public function process()
    {
        $this->processFields();

        $this->editableFields()->each(function (Field $field) {
            $field->placeholder($field->description());
            $field->setNewValue($this->getInput($field->elementName()));

            if ($field->hasValidNewValue()) {
                $field->applyFilter($this->query);
            }
        });

        if ($this->paginatorEnabled) {
            $this->paginator();
        }
    }
189569
protected function getFieldsToDelete()
    {
        $toDelete = array();

        $fields     = $this->_item->getFields();
        $origFields = $this->_item->getOrigFields();
        foreach ($origFields as $field => $value) {
            if (! array_key_exists($field, $fields)) {
                $toDelete[$field] = Update::DELETE_VALUE;
            }
        }

        return $toDelete;
    }
1274554
private function processFieldDefinition()
    {
        if (isset($this->definition['field'])) {
            $this->fields = $this->definition['field'];
        } elseif (isset($this->definition['fields'])) {
            $this->fields = $this->definition['fields'];
        } else {
            $this->fields = '*';
        }
    }
1306160
public function edit()
    {
        $this->new = false;
        $elements = $this->getElements();
        foreach ($this->getOriginalFields() as $field) {
            $this->add(array(
                'name' => 'original_' . $field,
                'attributes' => array(
                    'type' => 'hidden',
                    'value' => $elements[$field]->getValue(),
                )
            ));
            //$this->getFilter()->add(array(
            //    'name' => 'original_' . $field,
            //    'required' => true,
            //));
        }
        return $this;
    }
843432
protected function setTitleEditFieldValue()
    {
        if (isset($this->data_field_value['field_value_id'])) {
            $title = $this->text('Edit %name', array('%name' => $this->data_field_value['title']));
        } else {
            $title = $this->text('Add value for field %name', array('%name' => $this->data_field['title']));
        }

        $this->setTitle($title);
    }
299139
public function actionEdit() 
	{
		$model = OmmuMeta::model()->findByPk(1);
		if($model == null)
			$model=new OmmuMeta;

		// Uncomment the following line if AJAX validation is needed
		$this->performAjaxValidation($model);

		if(isset($_POST['OmmuMeta'])) {
			$model->attributes=$_POST['OmmuMeta'];
			$model->scenario = 'setting';
			
			if($model->save()) {
				Yii::app()->user->setFlash('success', Yii::t('phrase', 'Global Meta success updated.'));
				$this->redirect(array('edit'));
			}
		}

		$this->pageTitle = Yii::t('phrase', 'Meta Settings');
		$this->pageDescription = '';
		$this->pageMeta = '';
		$this->render('admin_edit', array(
			'model'=>$model,
		));
	}
936450
public function edit()
    {
        if (!userHasPermission('admin:invoice:invoice:edit')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oUri   = Factory::service('Uri');
        $oInput = Factory::service('Input');

        $iInvoiceId            = (int) $oUri->segment(5);
        $oModel                = $this->oInvoiceModel;
        $this->data['invoice'] = $oModel->getById(
            $iInvoiceId,
            ['expand' => $oModel::EXPAND_ALL]
        );

        if (!$this->data['invoice'] || $this->data['invoice']->state->id != 'DRAFT') {
            show404();
        }

        // --------------------------------------------------------------------------

        //  Page Title
        $this->data['page']->title = 'Edit Invoice &rsaquo; ' . $this->data['invoice']->ref;

        // --------------------------------------------------------------------------

        if ($oInput->post()) {
            if ($this->validatePost()) {
                if ($oModel->update($this->data['invoice']->id, $this->getObjectFromPost())) {

                    //  Send invoice if needed
                    $oInvoice = $oModel->getById($this->data['invoice']->id);
                    $this->sendInvoice($oInvoice);

                    $oSession = Factory::service('Session', 'nails/module-auth');
                    $oSession->setFlashData('success', 'Invoice was saved successfully.');

                    redirect('admin/invoice/invoice/index');

                } else {
                    $this->data['error'] = 'Failed to update invoice. ' . $oModel->lastError();
                }
            } else {
                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Page data
        $aItemUnits = $this->oInvoiceItemModel->getUnits();
        $aTaxes     = $this->oTaxModel->getAll();

        $this->data['invoiceStates'] = $oModel->getSelectableStates();

        // --------------------------------------------------------------------------

        //  Invoice Items
        if ($oInput->post()) {

            $aItems = $oInput->post('items') ?: [];
            //  Tidy up post data as expected by JS
            foreach ($aItems as &$aItem) {

                $aItem['label'] = html_entity_decode($aItem['label'], ENT_QUOTES, 'UTF-8');
                $aItem['body']  = html_entity_decode($aItem['body'], ENT_QUOTES, 'UTF-8');

                $sUnitCost                     = $aItem['unit_cost'];
                $aItem['unit_cost']            = new \stdClass();
                $aItem['unit_cost']->formatted = new \stdClass();
                $aItem['unit_cost']->formatted = !empty($sUnitCost) ? $sUnitCost : null;

                $aItem['tax']     = new \stdClass();
                $aItem['tax']->id = !empty($aItem['tax_id']) ? (int) $aItem['tax_id'] : null;

                $sUnit             = !empty($aItem['unit']) ? $aItem['unit'] : null;
                $aItem['unit']     = new \stdClass();
                $aItem['unit']->id = $sUnit;
            }

        } else {
            $aItems = $this->data['invoice']->items->data;
        }

        // --------------------------------------------------------------------------

        $oCurrency                = Factory::service('Currency', 'nails/module-currency');
        $aCurrencies              = $oCurrency->getAllEnabled();
        $this->data['currencies'] = $aCurrencies;
        //  A customer ID can be specified when creating an invoice; this prevents undefined var errors
        $this->data['customer_id'] = null;

        // --------------------------------------------------------------------------

        $oAsset = Factory::service('Asset');
        //  @todo (Pablo - 2018-11-30) - Load the minified version once the JS bundling has been sorted
        $oAsset->load('invoice.edit.js', 'nails/module-invoice');
        $oAsset->inline(
            'ko.applyBindings(
                new invoiceEdit(
                    ' . json_encode($aItemUnits) . ',
                    ' . json_encode($aTaxes) . ',
                    ' . json_encode($aItems) . ',
                    ' . json_encode($aCurrencies) . '
                )
            );',
            'JS'
        );

        //  Load views
        Helper::loadView('edit');
    }
201752
protected function getDisplayRuleFields()
    {
        // Check display rules
        if ($this->Required) {
            return FieldList::create(
                LiteralField::create(
                    'DisplayRulesNotEnabled',
                    '<div class="alert alert-warning">' . _t(
                        __CLASS__.'.DISPLAY_RULES_DISABLED',
                        'Display rules are not enabled for required fields. Please uncheck "Is this field Required?" under "Validation" to re-enable.'
                    ) . '</div>'
                )
            );
        }

        $allowedClasses = array_keys($this->getEditableFieldClasses(false));
        $editableColumns = new GridFieldEditableColumns();
        $editableColumns->setDisplayFields([
            'ConditionFieldID' => function ($record, $column, $grid) use ($allowedClasses) {
                    return DropdownField::create($column, '', EditableFormField::get()->filter([
                            'ParentID' => $this->ParentID,
                            'ClassName' => $allowedClasses,
                        ])->exclude([
                            'ID' => $this->ID,
                        ])->map('ID', 'Title'));
            },
            'ConditionOption' => function ($record, $column, $grid) {
                $options = Config::inst()->get(EditableCustomRule::class, 'condition_options');

                return DropdownField::create($column, '', $options);
            },
            'FieldValue' => function ($record, $column, $grid) {
                return TextField::create($column);
            }
        ]);

        // Custom rules
        $customRulesConfig = GridFieldConfig::create()
            ->addComponents(
                $editableColumns,
                new GridFieldButtonRow(),
                new GridFieldToolbarHeader(),
                new GridFieldAddNewInlineButton(),
                new GridFieldDeleteAction()
            );

        return new FieldList(
            DropdownField::create(
                'ShowOnLoad',
                _t(__CLASS__.'.INITIALVISIBILITY', 'Initial visibility'),
                [
                    1 => 'Show',
                    0 => 'Hide',
                ]
            ),
            DropdownField::create(
                'DisplayRulesConjunction',
                _t(__CLASS__.'.DISPLAYIF', 'Toggle visibility when'),
                [
                    'Or'  => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFOR', 'Any conditions are true'),
                    'And' => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFAND', 'All conditions are true'),
                ]
            ),
            GridField::create(
                'DisplayRules',
                _t(__CLASS__.'.CUSTOMRULES', 'Custom Rules'),
                $this->DisplayRules(),
                $customRulesConfig
            )
        );
    }
1294387
function delete_field() {
        global $DB;

        if (!empty($this->field->id)) {
            // Get the field before we delete it.
            $field = $DB->get_record('data_fields', array('id' => $this->field->id));

            $this->delete_content();
            $DB->delete_records('data_fields', array('id'=>$this->field->id));

            // Trigger an event for deleting this field.
            $event = \mod_data\event\field_deleted::create(array(
                'objectid' => $this->field->id,
                'context' => $this->context,
                'other' => array(
                    'fieldname' => $this->field->name,
                    'dataid' => $this->data->id
                 )
            ));
            $event->add_record_snapshot('data_fields', $field);
            $event->trigger();
        }

        return true;
    }
1128857
private function handleInputNameForEditAll()
    {
        if (('select' !== $this->getEnvironment()->getInputProvider()->getParameter('act'))
            && ('edit' !== $this->getEnvironment()->getInputProvider()->getParameter('select'))
            && ('edit' !== $this->getEnvironment()->getInputProvider()->getParameter('mode'))
        ) {
            return;
        }

        $tableName      = \explode('____', $this->getEnvironment()->getInputProvider()->getValue('name'))[0];
        $sessionKey     = 'DC_GENERAL_' . \strtoupper($tableName);
        $sessionStorage =
            System::getContainer()->get('cca.dc-general.session_factory')->createService()->setScope($sessionKey);

        $selectAction = $this->getEnvironment()->getInputProvider()->getParameter('select');

        $session = $sessionStorage->get($tableName . '.' . $selectAction);

        $originalPropertyName = null;
        foreach ((array) $session['models'] as $modelId) {
            if (null !== $originalPropertyName) {
                break;
            }

            $propertyNamePrefix = \str_replace('::', '____', $modelId) . '_';
            if (0 !== strpos($this->strName, $propertyNamePrefix)) {
                continue;
            }

            $originalPropertyName = \substr($this->strName, \strlen($propertyNamePrefix));
        }

        if (!$originalPropertyName) {
            return;
        }

        $this->arrConfiguration['originalField'] = $originalPropertyName;

        $this->strName = $propertyNamePrefix . '[' . $originalPropertyName . ']';
    }
1212122
public function cgetFieldsAction()
    {
        $fieldDescriptors = $this->getFieldDescriptors();

        return $this->handleView($this->view(array_values($fieldDescriptors)));
    }
311703
public function renderChildren()
    {
        if ($this->renderChildrenClosure !== null) {
            $closure = $this->renderChildrenClosure;
            return $closure();
        }
        return $this->viewHelperNode->evaluateChildNodes($this->renderingContext);
    }
1238017
public function Field($properties = array())
    {
        $context = $this;
        $properties['Editable'] = $this->editable;
        $properties['Reservation'] = $this->getReservation();
        $properties['Attendees'] = $this->editable
            ? $this->getEditableAttendees()
            : $this->getReservation()->Attendees();

        if (count($properties)) {
            $context = $context->customise($properties);
        }

        $this->extend('onBeforeRender', $context);

        $result = $context->renderWith($this->getTemplates());

        if (is_string($result)) {
            $result = trim($result);
        } else {
            if ($result instanceof DBField) {
                $result->setValue(trim($result->getValue()));
            }
        }

        return $result;
    }