本文整理匯總了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;
}