本文整理汇总了PHP中Drupal\Core\Field\FieldDefinitionInterface::isRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDefinitionInterface::isRequired方法的具体用法?PHP FieldDefinitionInterface::isRequired怎么用?PHP FieldDefinitionInterface::isRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldDefinitionInterface
的用法示例。
在下文中一共展示了FieldDefinitionInterface::isRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formSingleElement
/**
* Generates the form element for a single copy of the widget.
*/
protected function formSingleElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
{
$entity = $items->getEntity();
$element += array('#field_parents' => $form['#parents'], '#required' => $delta == 0 && $this->fieldDefinition->isRequired(), '#delta' => $delta, '#weight' => $delta);
$element = $this->formElement($items, $delta, $element, $form, $form_state);
if ($element) {
// Allow modules to alter the field widget form element.
$context = array('form' => $form, 'widget' => $this, 'items' => $items, 'delta' => $delta, 'default' => $this->isDefaultValueWidget($form_state));
\Drupal::moduleHandler()->alter(array('field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'), $element, $form_state, $context);
}
return $element;
}
示例2: isApplicable
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition)
{
if (!$field_definition->isRequired()) {
return FALSE;
}
$handler_settings = $field_definition->getSettings()['handler_settings'];
// Entity types without bundles will throw notices on next condition so let's
// stop before they do. We should support this kind of entities too. See
// https://www.drupal.org/node/2569193 and remove this check once that issue
// lands.
if (empty($handler_settings['target_bundles'])) {
return FALSE;
}
if (count($handler_settings['target_bundles']) != 1) {
return FALSE;
}
return TRUE;
}