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