/** * {@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; }
/** * {@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; }