/** * Overriden to permit multiple row same-model forms (admin_multi_edit) to work * Slightly none-DRY to prevent any changes to the cake method from affecting * normal form elements * * @return array An array containing the identity elements of an entity */ public function entity() { $assoc = $this->association ? $this->association : $this->model; if (!empty($this->entityPath)) { $path = explode('.', $this->entityPath); $count = count($path); if ($count !== 3) { return parent::entity(); } return Set::filter($path); } return parent::entity(); }
/** * Gets the data for the current tag * * @param mixed $options If an array, should be an array of attributes that $key needs to be added to. * If a string or null, will be used as the View entity. * @param string $field * @param string $key The name of the attribute to be set, defaults to 'value' * @return mixed If an array was given for $options, an array with $key set will be returned. * If a string was supplied a string will be returned. * @access public * @todo Refactor this method to not have as many input/output options. */ public function value($options = array(), $field = null, $key = 'value') { if ($options === null) { $options = array(); } elseif (is_string($options)) { $field = $options; $options = 0; } if (is_array($options) && isset($options[$key])) { return $options; } if (!empty($field)) { $this->setEntity($field); } $result = null; $data = $this->request->data; $entity = $this->_View->entity(); if (!empty($data) && !empty($entity)) { $result = Set::extract($data, join('.', $entity)); } $habtmKey = $this->field(); if (empty($result) && isset($data[$habtmKey][$habtmKey]) && is_array($data[$habtmKey])) { $result = $data[$habtmKey][$habtmKey]; } elseif (empty($result) && isset($data[$habtmKey]) && is_array($data[$habtmKey])) { if (ClassRegistry::isKeySet($habtmKey)) { $model =& ClassRegistry::getObject($habtmKey); $result = $this->__selectedArray($data[$habtmKey], $model->primaryKey); } } if (is_array($result)) { if (array_key_exists($this->_View->fieldSuffix, $result)) { $result = $result[$this->_View->fieldSuffix]; } } if (is_array($options)) { if ($result === null && isset($options['default'])) { $result = $options['default']; } unset($options['default']); } if (is_array($options)) { $options[$key] = $result; return $options; } else { return $result; } }