class FlexiformElementField_entityreference in Flexiform 7
Class for entityreference Field API elements.
Hierarchy
- class \FlexiformElement implements FlexiformElementInterface
- class \FlexiformElementField implements FlexiformElementFieldAPIInterface
Expanded class hierarchy of FlexiformElementField_entityreference
File
- includes/
element/ fields/ entityreference.inc, line 10 - Contains FlexiformElementField_entityreference class.
View source
class FlexiformElementField_entityreference extends FlexiformElementField {
/**
* {@inheritdoc}
*/
public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
$form = parent::form($form, $form_state, $entity, $language);
if ($this
->getWidgetType() == 'entityreference_autocomplete') {
foreach (element_children($form[$this->element_namespace][$language]) as $delta) {
$element =& $form[$this->element_namespace][$language][$delta]['target_id'];
$this
->formAlterAutocompleteElement($element, $entity);
}
}
else {
if ($this
->getWidgetType() == 'entityreference_autocomplete_tags') {
$this
->formAlterAutocompleteElement($form[$this->element_namespace][$language], $entity);
}
}
return $form;
}
/**
* Alter the selection element.
*/
protected function formAlterAutocompleteElement(&$element, $entity) {
$ac_path = $this
->getWidgetType() == 'entityreference_autocomplete' ? 'flexiform/entityreference/autocomplete/single' : 'flexiform/entityreference/autocomplete/tags';
$element['#autocomplete_path'] = $ac_path . '/' . $this->flexiform->form . '/' . $this->element_namespace;
if ($entity_id = entity_id($this->entity_type, $entity)) {
$element['#autocomplete_path'] .= "/{$entity_id}";
}
else {
$element['#autocomplete_path'] .= "/NULL";
}
foreach ($element['#element_validate'] as &$callback) {
if ($callback == '_entityreference_autocomplete_validate') {
$callback = array(
$this,
'autocompleteValidate',
);
}
if ($callback == '_entityreference_autocomplete_tags_validate') {
$callback = array(
$this,
'autocompleteTagsValidate',
);
}
}
}
/**
* {@inheritdoc}
*/
public function formSubmit($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
parent::formSubmit($form, $form_state, $entity, $language);
// Make us compatible with the inline_entity_form module.
// @todo: Consider just invoking this by default.
if (module_exists('inline_entity_form')) {
inline_entity_form_field_attach_submit($this
->getEntityType(), $entity, $this
->extractFormElements($form), $form_state);
}
return $form;
}
/**
* Validate any autocomplete input.
*
* @see _entityreference_autocomplete_validate
*/
public function autocompleteValidate($element, &$form_state, $form) {
$value = '';
if (!empty($element['#value'])) {
// Take "label (entity id)", match the id from parenthesis
if (preg_match("/.+\\((\\d+)\\)/", $element['#value'], $matches)) {
$value = $matches[1];
}
else {
// Try to get a match from the input string when the user didn't use the
// autocomplete but filled in a value manually.
$field = $this
->getField();
$instance = $this
->getInstance();
$handler = entityreference_get_selection_handler($field, $instance, $element['#entity_type'], $element['#entity']);
$value = $handler
->validateAutocompleteInput($element['#value'], $element, $form_state, $form);
}
}
form_set_value($element, $value, $form_state);
}
/**
* Validate tags autocomplete input.
*
* @see _entityreference_autocomplete_tags_validate
*/
public function autocompleteTagsValidate($element, &$form_state, $form) {
$value = array();
// If a value was entered into the autocomplete...
if (!empty($element['#value'])) {
$entities = drupal_explode_tags($element['#value']);
foreach ($entities as $entity) {
if (preg_match("/.+\\((\\d+)\\)/", $entity, $matches)) {
$value[] = array(
'target_id' => $matches[1],
);
}
else {
$field = $this
->getField();
$instance = $this
->getInstance();
$handler = entityreference_get_selection_handler($field, $instance, $element['#entity_type'], $element['#entity']);
$value[] = array(
'target_id' => $handler
->validateAutocompleteInput($entity, $element, $form_state, $form),
);
}
}
}
form_set_value($element, $value, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlexiformElement:: |
protected | property | The bundle this is on. | |
FlexiformElement:: |
protected | property | The namespace of this element. | |
FlexiformElement:: |
protected | property | The entity namespace of the entity this element is acting on. | |
FlexiformElement:: |
protected | property | The entity type this field is on. | |
FlexiformElement:: |
protected | property | The flexiform entity this element is one. | |
FlexiformElement:: |
protected | property | The settings for this element. | |
FlexiformElement:: |
protected | property | The weight of this element. | |
FlexiformElement:: |
public static | function | Create an element object. | |
FlexiformElement:: |
public | function | Get an array of ctools context for the flexiform. | |
FlexiformElement:: |
public | function | Build a list of possible ctools substitutions. | |
FlexiformElement:: |
public static | function | Get an element object. | |
FlexiformElement:: |
public | function | Get the element namespace for this form element. | |
FlexiformElement:: |
public | function | Get the entity namespace for this form element. | |
FlexiformElement:: |
public | function | Get the entity type for this element. | |
FlexiformElement:: |
public | function | Get the settings. | |
FlexiformElement:: |
public | function | Get the weight of this form element. | |
FlexiformElement:: |
public | function | Make namespace for the element. | 1 |
FlexiformElement:: |
public | function | Get the name for this form element. | |
FlexiformElement:: |
public | function | Build the remove form for the element. | |
FlexiformElement:: |
public | function | Submit the remove form for the element. | |
FlexiformElement:: |
public | function | Validate the remove form for the element. | |
FlexiformElement:: |
public | function | Replace ctools substitutions with their values. | |
FlexiformElementField:: |
protected | property | The field settings for the field. | |
FlexiformElementField:: |
protected | property | The field name of the field. | |
FlexiformElementField:: |
protected | property | The instance settings for the field | |
FlexiformElementField:: |
public | function | Check widget behavior. | |
FlexiformElementField:: |
public | function | Add the Field Settings section to the config form. | |
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::configureForm(). Overrides FlexiformElement:: |
1 |
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::configureFormSubmit(). Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::configureFormValidate(). Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function | Get the Difference of two settings arrays. | |
FlexiformElementField:: |
function | Extract the form element from $form and give it the correct key. | ||
FlexiformElementField:: |
protected | function | Invoke field hooks on a specific field. | |
FlexiformElementField:: |
protected | function | Invoke default field hooks on this element. | |
FlexiformElementField:: |
function |
Overrides FlexiformElement::formExtractValues(). Overrides FlexiformElement:: |
||
FlexiformElementField:: |
function |
Overrides FlexiformElement::formIsEmpty(). Overrides FlexiformElement:: |
||
FlexiformElementField:: |
public | function |
Validate this element. Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Get the field array. Overrides FlexiformElementFieldAPIInterface:: |
|
FlexiformElementField:: |
public | function |
Get the instance array. Overrides FlexiformElementFieldAPIInterface:: |
|
FlexiformElementField:: |
public | function | Get the widget label from the instance settings. | |
FlexiformElementField:: |
public | function | Get the widget type from the instance settings. | |
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::label(). Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::setLabel(). Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Set the weight of this form element. Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Overrides FlexifromElement::toSettingsArray(); Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Return the type. Overrides FlexiformElement:: |
|
FlexiformElementField:: |
public | function |
Overrides FlexiformElement::__construct(). Overrides FlexiformElement:: |
|
FlexiformElementField_entityreference:: |
public | function | Validate tags autocomplete input. | |
FlexiformElementField_entityreference:: |
public | function | Validate any autocomplete input. | |
FlexiformElementField_entityreference:: |
public | function |
Return the form element for this FlexiformElement. Overrides FlexiformElementField:: |
|
FlexiformElementField_entityreference:: |
protected | function | Alter the selection element. | |
FlexiformElementField_entityreference:: |
public | function |
Submit callback for this form. Overrides FlexiformElementField:: |