本文整理汇总了PHP中Drupal\Core\Field\FieldItemListInterface::getLangcode方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemListInterface::getLangcode方法的具体用法?PHP FieldItemListInterface::getLangcode怎么用?PHP FieldItemListInterface::getLangcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldItemListInterface
的用法示例。
在下文中一共展示了FieldItemListInterface::getLangcode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formElement
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
{
$OriginalValue = '';
if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
$FiledsView = $items->view();
$LangCode = $items->getLangcode();
$FieldName = $FiledsView['#field_name'];
$node = (array) $node;
$arrayValues = array_values($node);
if (isset($arrayValues[0]['langcode']['x-default']) && $arrayValues[0]['langcode']['x-default'] != $LangCode) {
if ($FieldName != 'title') {
if (isset($arrayValues[0][$FieldName]['x-default'][0]['value'])) {
$OriginalValue = $arrayValues[0][$FieldName]['x-default'][0]['value'];
}
} else {
if (isset($arrayValues[0][$FieldName]['x-default'])) {
$OriginalValue = $arrayValues[0][$FieldName]['x-default'];
}
}
$Title = $OriginalValue;
$OriginalValue = Unicode::truncate($OriginalValue, 200, TRUE);
$OriginalValue = '<div class="original_text" title="' . $Title . '"><span class="original">ORIGINAL: </span>' . $OriginalValue . '</div>';
}
}
$element['value'] = $element + array('#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => $this->getFieldSetting('max_length'), '#attributes' => array('class' => array('text-full')), '#suffix' => $OriginalValue);
return $element;
}
示例2: formElement
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
{
$entity = $items->getEntity();
$path = array();
if (!$entity->isNew()) {
$conditions = array('source' => '/' . $entity->urlInfo()->getInternalPath());
if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$conditions['langcode'] = $items->getLangcode();
}
$path = \Drupal::service('path.alias_storage')->load($conditions);
if ($path === FALSE) {
$path = array();
}
}
$path += array('pid' => NULL, 'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL, 'alias' => '', 'langcode' => $items->getLangcode());
$element += array('#element_validate' => array(array(get_class($this), 'validateFormElement')));
$element['alias'] = array('#type' => 'textfield', '#title' => $element['#title'], '#default_value' => $path['alias'], '#required' => $element['#required'], '#maxlength' => 255, '#description' => $this->t('The alternative URL for this content. Use a relative path. For example, enter "/about" for the about page.'));
$element['pid'] = array('#type' => 'value', '#value' => $path['pid']);
$element['source'] = array('#type' => 'value', '#value' => $path['source']);
$element['langcode'] = array('#type' => 'value', '#value' => $path['langcode']);
return $element;
}