Resolves option from fields

@param FieldInterface[] $fields
@param $option
@param mixed $expected
@return mixed
330899
protected function resolveFieldOption(array $fields, $option, $expected = true)
    {
        foreach ($fields as $field) {
            if ($field->getOption($option) === $expected) {
                return $expected;
            }
        }

        return null;
    }
1043474
public function matches($expectedvalue) {

        $multiple = $this->field->hasAttribute('multiple');

        // Same implementation as the parent if it is a single select.
        if (!$multiple) {
            $cleanexpectedvalue = trim($expectedvalue);
            $selectedtext = trim($this->get_selected_options());
            $selectedvalue = trim($this->get_selected_options(false));
            if ($cleanexpectedvalue != $selectedvalue && $cleanexpectedvalue != $selectedtext) {
                return false;
            }
            return true;
        }

        // We are dealing with a multi-select.

        // Unescape + trim all options and flip it to have the expected values as keys.
        $expectedoptions = $this->get_unescaped_options($expectedvalue);

        // Get currently selected option's texts.
        $texts = $this->get_selected_options(true);
        $selectedoptiontexts = $this->get_unescaped_options($texts);

        // Get currently selected option's values.
        $values = $this->get_selected_options(false);
        $selectedoptionvalues = $this->get_unescaped_options($values);

        // We check against string-ordered lists of options.
        if ($expectedoptions !== $selectedoptiontexts &&
                $expectedoptions !== $selectedoptionvalues) {
            return false;
        }

        return true;
    }
769856
public function hiddenFieldValueEquals($field, $value)
    {
        $node = $this->findHiddenField($field);
        $actual = $node->getValue();
        $regex = '/^' . preg_quote($value, '/') . '/ui';

        if (!preg_match($regex, $actual)) {
            $message = sprintf('The hidden field "%s" value is "%s", but "%s" expected.', $field, $actual, $value);

            throw new ExpectationException($message, $this->getSession());
        }
    }
471698
def resolved_option(options, target, key):
    
    option_value = options.get(key)
    if not isinstance(target, AppBase) or options.is_flagged(key):
      return option_value
    v = target.payload.get_field_value(key, None)
    return option_value if v is None else v
263143
public function resolveField(FieldValue $value): FieldValue
    {
        return $value->setResolver(
            function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Deferred {
                $constructorArgs = [
                    'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
                    'args' => $args,
                    'scopes' => $this->directiveArgValue('scopes', []),
                    'resolveInfo' => $resolveInfo,
                ];

                if ($paginationType = $this->paginationType()) {
                    /** @var int $first */
                    /** @var int $page */
                    [$first, $page] = PaginationUtils::extractArgs($args, $paginationType, $this->paginateMaxCount());

                    $constructorArgs += [
                        'first' => $first,
                        'page' => $page,
                    ];
                }

                return BatchLoader
                    ::instance(
                        RelationBatchLoader::class,
                        $resolveInfo->path,
                        $constructorArgs
                    )
                    ->load(
                        $parent->getKey(),
                        ['parent' => $parent]
                    );
            }
        );
    }
648007
final public static function validateNumericFields (array $fields=[], string $option, string $field) : bool
	{
		$fieldsWithError 	= "";
		$field 				= static::checkGlobal($field);
		foreach ($fields as $fieldName => $length)
		{
			$value = static::setValueNull($field[$fieldName]);
			if ($value !== NULL) {
				$options = [$option => $length];
				if (!static::hasNumber($value, $options))
					$fieldsWithError .= "'".fieldNameAsText($fieldName)."', ";
			}
		}
		static::setError($fieldsWithError);
		return static::checkError();
	}
763656
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $value = $next($value);

        $resolver = $value->getResolver();

        return $value->setResolver(function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver) {
            $start = $this->tracing->getTime();

            $result = $resolver($root, $args, $context, $resolveInfo);

            $end = $this->tracing->getTime();

            if ($result instanceof Deferred) {
                $result->then(function () use ($resolveInfo, $start, $end): void {
                    $this->tracing->record($resolveInfo, $start, $end);
                });
            } else {
                $this->tracing->record($resolveInfo, $start, $end);
            }

            return $result;
        });
    }
1345355
public function matches($expectedvalue = false) {

        $ischecked = $this->field->isChecked();

        // Any non-empty value provided means that it should be checked.
        if (!empty($expectedvalue) && $ischecked) {
            return true;
        } else if (empty($expectedvalue) && !$ischecked) {
            return true;
        }

        return false;
    }
376761
public function assertSelectOptions($select, TableNode $options) {
    // Retrieve the specified field.
    if (!$field = $this->getSession()->getPage()->findField($select)) {
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
    }

    /* @var \Behat\Mink\Element\NodeElement $field */

    // Check that the specified field is a <select> field.
    $this->assertElementType($field, 'select');

    // Retrieve the options table from the test scenario and flatten it.
    $expected_options = $options->getColumnsHash();
    array_walk($expected_options, function (&$value) {
      $value = reset($value);
    });

    // Retrieve the actual options that are shown in the page.
    $actual_options = $field->findAll('css', 'option');

    // Convert into a flat list of option text strings.
    array_walk($actual_options, function (NodeElement &$value) {
      $value = $value->getText();
    });

    // Check that all expected options are present.
    foreach ($expected_options as $expected_option) {
      if (!in_array($expected_option, $actual_options)) {
        throw new ExpectationException("Option '$expected_option' is missing from select list '$select'.", $this->getSession());
      }
    }
  }
1225718
public function assertSelectHasOptions($field, array $values)
    {
        $options = $this->resolver->resolveSelectOptions($field, $values);

        $options = collect($options)->unique(function (RemoteWebElement $option) {
            return $option->getAttribute('value');
        })->all();

        PHPUnit::assertCount(
            count($values), $options,
            'Expected options ['.implode(',', $values)."] for selection field [{$field}] to be available."
        );

        return $this;
    }
222988
public function chosen($fieldName, $options = [])
    {
        $defaults = [
            'div' => [
                'class' => 'form-group',
            ],
            'class' => 'form-control form-control-chosen',
            'empty' => true,
        ];

        if (isset($options['class'])) {
            $defaults = parent::addClass($defaults, $options['class']);
            unset($options['class']);
        }
        $options = array_merge($defaults, $options);
        return parent::input($fieldName, $options);
    }
422491
public function set($fields = null)
    {
        if ($fields === null) {
            return $this->clause('set');
        }

        if (!in_array($this->action(), [self::ACTION_CREATE, self::ACTION_UPDATE])) {
            throw new \UnexpectedValueException(__('The action of this query needs to be either create update'));
        }

        $this->_parts['set'] = $fields;

        return $this;
    }
307013
public function assertFields(TableNode $expected) {
    $fields = [];
    foreach ($this->getContentEntityTypes() as $entity_type) {
      $bundles = $this->entityTypeManager()
        ->getStorage($entity_type->getBundleEntityType())
        ->loadMultiple();
      foreach ($bundles as $bundle) {
        /** @var string[] $ids */
        $ids = \Drupal::entityQuery('field_config')
          ->condition('bundle', $bundle->id())
          ->condition('entity_type', $entity_type->id())
          ->execute();

        if (!$ids) {
          continue;
        }

        $display_id = "{$entity_type->id()}.{$bundle->id()}.default";
        $form_display = EntityFormDisplay::load($display_id);
        if (is_null($form_display)) {
          throw new \Exception(sprintf('No such form display: %s. Try saving the "Manage form display" form for the "%s" %s.', $display_id, $bundle->label(), strtolower($entity_type->getBundleLabel())));
        }
        $form_components = $form_display->getComponents();

        /** @var \Drupal\field\FieldConfigInterface $field_config */
        foreach (FieldConfig::loadMultiple($ids) as $id => $field_config) {
          $machine_name = $this->getFieldMachineNameFromConfigId($id);
          $field_storage = $field_config->getFieldStorageDefinition();
          $fields[] = [
            $bundle->label(),
            $field_config->getLabel(),
            $machine_name,
            (string) $this->fieldTypeManager->getDefinition($field_config->getType())['label'],
            $field_config->isRequired() ? 'Required' : '',
            $field_storage->getCardinality() === -1 ? 'Unlimited' : $field_storage->getCardinality(),
            isset($form_components[$machine_name]['type']) ? (string) $this->fieldWidgetManager->getDefinition($form_components[$machine_name]['type'])['label'] : '-- Disabled --',
            $field_config->isTranslatable() ? 'Translatable' : '',
            $field_config->getDescription(),
          ];
        }
      }
    }
    $actual = new TableNode($fields);

    (new TableEqualityAssertion($expected, $actual))
      ->expectHeader([
        'Bundle',
        'Field label',
        'Machine name',
        'Field type',
        'Required',
        'Cardinality',
        'Form widget',
        'Translatable',
        'Help text',
      ])
      ->ignoreRowOrder()
      ->setMissingRowsLabel(self::missingRowsLabelFor('fields'))
      ->setUnexpectedRowsLabel(self::unexpectedRowsLabelFor('fields'))
      ->assert();
  }
1345187
protected function _resolveFields($fields)
    {
        if (is_string($fields)) {
            $fields = [$fields];
        }

        if (!is_array($fields)) {
            throw new Exception('Invalid "fields" configuration.');
        }

        $types = array_keys(Type::map());

        foreach ($fields as $field => $type) {
            if (is_numeric($field) && is_string($type)) {
                unset($fields[$field]);
                $field = $type;
                $type = self::DEFAULT_TYPE;
                $fields[$field] = $type;
            }

            if (!in_array($type, $types)) {
                throw new Exception(sprintf('The field "%s" mapped type "%s" was not found.', $field, $type));
            }
        }

        return $fields;
    }
715689
function Expectation (spec, options) {
  this.id = ++id;
  // Static fields:
  this.specification = spec;
  spec.expectations.push(this);
  this.stopOnFailure = spec.stopOnFailure;
  this.verbose = spec.verbose;
  // Optional fields:
  this.thunk = undefined;
  this.code = undefined;
  this.weight = 1;
  Object.assign(this, options || {});
  spec.description.log_("Expectation: " + this.actual);
  this.index = ++this.specification.index;
  this.specification.expectationAttempted += this.weight;
  // Internal (dynamic) fields:
  this.raisedException = false;
  this.exception = null;
  this.pass = false;
  this.runEndHook = false;
}
797265
public static function resolve($option)
    {
        if (isset(self::$curlOptions[$option])) {
            return [
                'type' => 'curl_option',
                'option' => self::$curlOptions[$option],
            ];
        } elseif (in_array($option, self::$lushOptions)) {
            return [
                'type' => 'lush_option',
                'option' => $option,
            ];
        }

        throw new LushException(sprintf("Invalid option '%s'", $option));
    }
901866
public function filterFields(FieldBag $fields)
    {
        $allFields = $this->getModule()->getOption('model_fields');

        $filteredFields = new FieldBag();
        foreach ($fields as $name => $field) {
            if (!$allFields->has($name)) {
                throw new \RuntimeException(sprintf('The field "%s" does not exist.', $name));
            }

            $filteredField = clone $field;
            foreach ($allFields->get($name)->getOptions() as $optionName => $optionValue) {
                if (!$filteredField->hasOption($optionName)) {
                    $filteredField->setOption($optionName, $optionValue);
                }
            }

            $filteredFields->set($name, $filteredField);
        }

        return $filteredFields;
    }