本文整理汇总了PHP中Drupal\Component\Utility\Html::getUniqueID方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::getUniqueID方法的具体用法?PHP Html::getUniqueID怎么用?PHP Html::getUniqueID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Html
的用法示例。
在下文中一共展示了Html::getUniqueID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formMultipleElements
/**
* {@inheritdoc}
*/
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
{
// Adjust wrapper identifiers as they are shared between parents and
// children in nested field collections.
$form['#wrapper_id'] = Html::getUniqueID($items->getName());
$elements = parent::formMultipleElements($items, $form, $form_state);
$elements['#prefix'] = '<div id="' . $form['#wrapper_id'] . '">';
$elements['#suffix'] = '</div>';
$elements['add_more']['#ajax']['wrapper'] = $form['#wrapper_id'];
return $elements;
}
示例2: formMultipleElements
/**
* {@inheritdoc}
*/
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
{
// We don't want to render empty items on field collection fields
// unless a) the field collection is empty ; b) the form is rebuilding,
// which means that the user clicked on "Add another item"; or
// c) we are creating a new entity.
if (count($items) > 0 && !$form_state->isRebuilding() && !$items->getEntity()->isNew()) {
$field_name = $this->fieldDefinition->getName();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$parents = $form['#parents'];
if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$field_state = static::getWidgetState($parents, $field_name, $form_state);
$field_state['items_count']--;
static::setWidgetState($parents, $field_name, $form_state, $field_state);
}
}
// Adjust wrapper identifiers as they are shared between parents and
// children in nested field collections.
$form['#wrapper_id'] = Html::getUniqueID($items->getName());
$elements = parent::formMultipleElements($items, $form, $form_state);
$elements['#prefix'] = '<div id="' . $form['#wrapper_id'] . '">';
$elements['#suffix'] = '</div>';
$elements['add_more']['#ajax']['wrapper'] = $form['#wrapper_id'];
return $elements;
}