/** * {@inheritdoc} */ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode) { $entity = $items->getEntity(); $field_name = $items->getFieldDefinition()->getName(); // Early-return if user does not have access. $access = $this->accessChecker->accessEditEntityField($entity, $field_name); if (!$access) { return array('access' => FALSE); } // Early-return if no editor is available. $formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId(); $editor_id = $this->editorSelector->getEditor($formatter_id, $items); if (!isset($editor_id)) { return array('access' => FALSE); } // Gather metadata, allow the editor to add additional metadata of its own. $label = $items->getFieldDefinition()->getLabel(); $editor = $this->editorManager->createInstance($editor_id); $metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label))); $custom_metadata = $editor->getMetadata($items); if (count($custom_metadata)) { $metadata['custom'] = $custom_metadata; } return $metadata; }
/** * Returns the in-place editor that Quick Edit selects. */ protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') { $entity = entity_load('entity_test', $entity_id, TRUE); $items = $entity->get($field_name); $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name); return $this->editorSelector->getEditor($options['type'], $items); }
/** * Returns the in-place editor that Quick Edit selects. */ protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') { $entity = entity_load('entity_test', $entity_id, TRUE); $items = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED)->get($field_name); $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name); return $this->editorSelector->getEditor($options['type'], $items); }
/** * Returns the in-place editor that Quick Edit selects. */ protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') { $storage = $this->container->get('entity_type.manager')->getStorage('entity_test'); $storage->resetCache([$entity_id]); $entity = $storage->load($entity_id); $items = $entity->get($field_name); $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name); return $this->editorSelector->getEditor($options['type'], $items); }
/** * Tests in-place editor attachments when the Editor module is present. */ public function testAttachments() { $this->editorSelector = $this->container->get('quickedit.editor.selector'); $editors = array('editor'); $attachments = $this->editorSelector->getEditorAttachments($editors); $this->assertIdentical($attachments, array('library' => array('editor/quickedit.inPlaceEditor.formattedText')), "Expected attachments for Editor module's in-place editor found."); }
/** * Returns AJAX commands to load in-place editors' attachments. * * Given a list of in-place editor IDs as POST parameters, render AJAX * commands to load those in-place editors. * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. */ public function attachments(Request $request) { $response = new AjaxResponse(); $editors = $request->request->get('editors'); if (!isset($editors)) { throw new NotFoundHttpException(); } $response->setAttachments($this->editorSelector->getEditorAttachments($editors)); return $response; }
/** * Returns AJAX commands to load in-place editors' attachments. * * Given a list of in-place editor IDs as POST parameters, render AJAX * commands to load those in-place editors. * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. */ public function attachments(Request $request) { $response = new AjaxResponse(); $editors = $request->request->get('editors'); if (!isset($editors)) { throw new NotFoundHttpException(); } $elements['#attached'] = $this->editorSelector->getEditorAttachments($editors); drupal_process_attached($elements); return $response; }