class FormState in Drupal 7 to 8/9 Module Upgrader 8
Plugin annotation
@Rewriter(
id = "form_state",
type_hint = "\Drupal\Core\Form\FormStateInterface",
properties = {
"always_process" = {
"get" = "getAlwaysProcess",
"set" = "setAlwaysProcess"
},
"build_info" = {
"get" = "getBuildInfo",
"set" = "setBuildInfo"
},
"buttons" = {
"get" = "getButtons",
"set" = "setButtons"
},
"cache" = {
"get" = "isCached",
"set" = "setCached"
},
"complete_form" = {
"get" = "getCompleteForm"
},
"executed" = {
"get" = "isExecuted",
"set" = "setExecuted"
},
"groups" = {
"get" = "getGroups",
"set" = "setGroups"
},
"has_file_element" = {
"get" = "hasFileElement",
"set" = "setHasFileElement"
},
"input" = {
"get" = "getUserInput",
"set" = "setUserInput"
},
"limit_validation_errors" = {
"get" = "getLimitValidationErrors",
"set" = "setLimitValidationErrors"
},
"must_validate" = {
"get" = "isValidationEnforced",
"set" = "setValidationEnforced"
},
"process_input" = {
"get" = "isProcessingInput",
"set" = "setProcessInput"
},
"programmed" = {
"get" = "isProgrammed",
"set" = "setProgrammed"
},
"programmed_bypass_access_check" = {
"get" = "isBypassingProgrammedAccessChecks",
"set" = "setProgrammedBypassAccessCheck"
},
"rebuild" = {
"get" = "isRebuilding",
"set" = "setRebuild"
},
"response" = {
"get" = "getResponse",
"set" = "setResponse"
},
"storage" = {
"get" = "getStorage",
"set" = "setStorage"
},
"submit_handlers" = {
"get" = "getSubmitHandlers",
"set" = "setSubmitHandlers"
},
"submitted" = {
"get" = "isSubmitted",
"set" = "getSubmitted"
},
"temporary" = {
"get" = "getTemporary",
"set" = "setTemporary"
},
"triggering_element" = {
"get" = "getTriggeringElement",
"set" = "setTriggeringElement"
},
"validate_handlers" = {
"get" = "getValidateHandlers",
"set" = "setValidateHandlers"
},
"validation_complete" = {
"get" = "isValidationComplete",
"set" = "setValidationComplete"
}
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\drupalmoduleupgrader\PluginBase implements ContainerFactoryPluginInterface
- class \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\Generic implements RewriterInterface
- class \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\FormState
- class \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\Generic implements RewriterInterface
- class \Drupal\drupalmoduleupgrader\PluginBase implements ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FormState
File
- src/
Plugin/ DMU/ Rewriter/ FormState.php, line 112
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\RewriterView source
class FormState extends Generic {
/**
* {@inheritdoc}
*/
public function rewrite(ParameterNode $parameter) {
parent::rewrite($parameter);
$function = $parameter
->getFunction();
$form_state = Token::variable('$' . $parameter
->getName());
$set_errors = $function
->find(Filter::isFunctionCall('form_set_error', 'form_error'));
/** @var \Pharborist\Functions\FunctionCallNode $set_error */
foreach ($set_errors as $set_error) {
$arguments = $set_error
->getArguments();
$method = $set_error
->getName()
->getText() == 'form_set_error' ? 'setErrorByName' : 'setError';
$rewrite = ObjectMethodCallNode::create(clone $form_state, $method);
foreach ($arguments as $argument) {
if (is_object($argument)) {
$rewrite
->appendArgument(clone $argument);
}
}
$set_error
->replaceWith($rewrite);
}
// form_clear_error() --> $form_state->clearErrors().
$clear_errors = $function
->find(Filter::isFunctionCall('form_clear_error'));
foreach ($clear_errors as $clear_error) {
$clear_error
->replaceWith(ObjectMethodCallNode::create(clone $form_state, 'clearErrors'));
}
// form_get_errors() --> $form_state->getErrors()
$get_errors = $function
->find(Filter::isFunctionCall('form_get_errors'));
foreach ($get_errors as $get_error) {
$get_error
->replaceWith(ObjectMethodCallNode::create(clone $form_state, 'getErrors'));
}
// form_get_error() --> $form_state->getError()
$get_errors = $function
->find(Filter::isFunctionCall('form_get_error'));
/** @var \Pharborist\Functions\FunctionCallNode $get_error */
foreach ($get_errors as $get_error) {
$rewrite = ObjectMethodCallNode::create(clone $form_state, 'getError')
->appendArgument($get_error
->getArguments()
->get(0));
$get_error
->replaceWith($rewrite);
}
}
/**
* {@inheritdoc}
*/
public function rewriteAsGetter(ExpressionNode $expr, $property) {
/** @var \Pharborist\ArrayLookupNode $expr */
$object = clone $expr
->getRootArray();
$keys = $expr
->getKeys();
// $foo = $form_state['values'] --> $foo = $form_state->getValues()
// $foo = $form_state['values']['baz'] --> $form_state->getValue(['baz'])
if ($property == 'values') {
if (sizeof($keys) == 1) {
return ObjectMethodCallNode::create($object, 'getValues');
}
else {
array_shift($keys);
return ObjectMethodCallNode::create($object, 'getValue')
->appendArgument(ArrayNode::create($keys));
}
}
elseif (isset($this->pluginDefinition['properties'][$property]['get'])) {
return parent::rewriteAsGetter($expr, $property);
}
else {
return ObjectMethodCallNode::create($object, 'get')
->appendArgument(ArrayNode::create($keys));
}
}
/**
* {@inheritdoc}
*/
public function rewriteAsSetter(ExpressionNode $expr, $property, AssignNode $assignment) {
/** @var \Pharborist\ArrayLookupNode $expr */
$object = clone $expr
->getRootArray();
$keys = $expr
->getKeys();
$value = clone $assignment
->getRightOperand();
// $form_state['values']['baz'] = 'foo' --> $form_state->setValue(['baz'], 'foo')
if ($property == 'values') {
array_shift($keys);
return ObjectMethodCallNode::create($object, 'setValue')
->appendArgument(ArrayNode::create($keys))
->appendArgument($value);
}
elseif (isset($this->pluginDefinition['properties'][$property]['set'])) {
return parent::rewriteAsSetter($expr, $property, $assignment);
}
else {
return ObjectMethodCallNode::create($object, 'set')
->appendArgument(ArrayNode::create($keys))
->appendArgument($value);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormState:: |
public | function |
Parametrically rewrites the function containing the given parameter. Overrides Generic:: |
|
FormState:: |
public | function |
Rewrites the given expression as a property getter. Returns NULL if the
expression cannot be rewritten. Overrides Generic:: |
|
FormState:: |
public | function |
Rewrites an assignment expression as a property setter. Returns NULL if
the expression cannot be rewritten. Overrides Generic:: |
|
Generic:: |
protected | property | ||
Generic:: |
protected | function | Finds every rewritable expression in the function body. | |
Generic:: |
protected | function | Returns the property used by a rewritable expression, or NULL if the property cannot be determined. | |
Generic:: |
protected | function | Returns if the parameter is fully reassigned anywhere in the function. | |
Generic:: |
public static | function | Checks if a field lookup key is translated. This will be TRUE unless one of the following conditions applies: | |
Generic:: |
public static | function | Rewrites a Drupal 7 field lookup like so: | |
Generic:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | ||
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |