diff --git a/core/modules/comment/comment.field.inc b/core/modules/comment/comment.field.inc deleted file mode 100644 index 74593c6..0000000 --- a/core/modules/comment/comment.field.inc +++ /dev/null @@ -1,132 +0,0 @@ - array( - 'label' => t('Comments'), - 'description' => t('This field manages configuration and presentation of comments on an entity'), - 'instance_settings' => array( - // Save this settings to allow other modules to migrate their data. - // @todo The "comment_default" formatter settings should used instead. - 'default_mode' => COMMENT_MODE_THREADED, - 'per_page' => 50, - 'form_location' => COMMENT_FORM_BELOW, - // Comment form settings per field bundle. - 'anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT, - 'subject' => 1, - 'preview' => DRUPAL_OPTIONAL, - ), - 'default_widget' => 'comment_default', - 'default_formatter' => 'comment_default', - 'field item class' => 'Drupal\comment\Type\CommentItem', - ) - ); -} - -/** - * Implements hook_field_instance_settings_form(). - */ -function comment_field_instance_settings_form($field, $instance) { - $settings = $instance['settings']; - $form['comment'] = array( - '#type' => 'details', - '#title' => t('Comment form settings'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - '#field_name' => $field['field_name'], - '#process' => array('_comment_field_instance_settings_form_process'), - '#attributes' => array( - 'class' => array('comment-instance-settings-form'), - ), - '#attached' => array( - 'library' => array(array('comment', 'drupal.comment')), - ), - ); - $form['comment']['default_mode'] = array( - '#type' => 'checkbox', - '#title' => t('Threading'), - '#default_value' => $settings['default_mode'], - '#description' => t('Show comment replies in a threaded list.'), - ); - $form['comment']['per_page'] = array( - '#type' => 'select', - '#title' => t('Comments per page'), - '#default_value' => $settings['per_page'], - '#options' => _comment_per_page(), - ); - $form['comment']['anonymous'] = array( - '#type' => 'select', - '#title' => t('Anonymous commenting'), - '#default_value' => $settings['anonymous'], - '#options' => array( - COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'), - COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'), - COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'), - ), - '#access' => user_access('post comments', drupal_anonymous_user()), - ); - $form['comment']['subject'] = array( - '#type' => 'checkbox', - '#title' => t('Allow comment title'), - '#default_value' => $settings['subject'], - ); - $form['comment']['form_location'] = array( - '#type' => 'checkbox', - '#title' => t('Show reply form on the same page as comments'), - '#default_value' => $settings['form_location'], - ); - $form['comment']['preview'] = array( - '#type' => 'radios', - '#title' => t('Preview comment'), - '#default_value' => $settings['preview'], - '#options' => array( - DRUPAL_DISABLED => t('Disabled'), - DRUPAL_OPTIONAL => t('Optional'), - DRUPAL_REQUIRED => t('Required'), - ), - ); - return $form; -} - -/** - * Process callback to add submit handler for instance settings form. - * - * Attaches the required translation entity handlers for the instance which - * correlates one to one with the comment bundle. - */ -function _comment_field_instance_settings_form_process($element, $form_state) { - // Settings should not be stored as nested. - $parents = $element['#parents']; - array_pop($parents); - $element['#parents'] = $parents; - // Add translation entity handlers. - if (Drupal::moduleHandler()->moduleExists('translation_entity')) { - $comment_form = $element; - $comment_form_state['translation_entity']['key'] = 'language_configuration'; - $element += translation_entity_enable_widget('comment', $element['#field_name'], $comment_form, $comment_form_state); - $element['translation_entity']['#parents'] = $element['translation_entity']['#array_parents'] = array( - 'translation_entity' - ); - } - return $element; -} - -/** - * Implements hook_field_is_empty(). - */ -function comment_field_is_empty($item, $field) { - // We always want the values saved so we can rely on them. - return FALSE; -} diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 0aa5938..ae780f0 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -332,22 +332,6 @@ function comment_schema() { } /** - * Implements hook_field_schema(). - */ -function comment_field_schema($field) { - return array( - 'columns' => array( - 'status' => array( - 'description' => 'Whether comments are allowed on this entity: 0 = no, 1 = closed (read only), 2 = open (read/write).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - ); -} - -/** * @addtogroup updates-7.x-to-8.x * @{ */ diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1883799..7c7c7ed 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -21,9 +21,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Drupal\Core\Language\Language; -// Load all Field module hooks for Comment. -require __DIR__ . '/comment.field.inc'; - /** * Comment is awaiting approval. */ @@ -2019,3 +2016,26 @@ function _comment_get_default_status($values) { // We only ever process first value if any. return isset($values[0]['status']) ? $values[0]['status'] : COMMENT_OPEN; } + +/** + * Process callback to add submit handler for instance settings form. + * + * Attaches the required translation entity handlers for the instance which + * correlates one to one with the comment bundle. + */ +function _comment_field_instance_settings_form_process($element, $form_state) { + // Settings should not be stored as nested. + $parents = $element['#parents']; + array_pop($parents); + $element['#parents'] = $parents; + // Add translation entity handlers. + if (Drupal::moduleHandler()->moduleExists('translation_entity')) { + $comment_form = $element; + $comment_form_state['translation_entity']['key'] = 'language_configuration'; + $element += translation_entity_enable_widget('comment', $element['#field_name'], $comment_form, $comment_form_state); + $element['translation_entity']['#parents'] = $element['translation_entity']['#array_parents'] = array( + 'translation_entity' + ); + } + return $element; +} diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php new file mode 100644 index 0000000..4a21bba --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php @@ -0,0 +1,162 @@ + 'integer', + 'label' => t('Comment status value'), + 'settings' => array('default_value' => COMMENT_OPEN), + ); + } + return static::$propertyDefinitions; + } + + /** + * {@inheritdoc} + */ + public static function schema(Field $field) { + return array( + 'columns' => array( + 'status' => array( + 'description' => 'Whether comments are allowed on this entity: 0 = no, 1 = closed (read only), 2 = open (read/write).', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function instanceSettingsForm(array $form, array &$form_state) { + $element = array(); + + $settings = $this->getInstance()->settings; + $field = $this->getInstance()->getField(); + + $element['comment'] = array( + '#type' => 'details', + '#title' => t('Comment form settings'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#field_name' => $field->id(), + '#process' => array('_comment_field_instance_settings_form_process'), + '#attributes' => array( + 'class' => array('comment-instance-settings-form'), + ), + '#attached' => array( + 'library' => array(array('comment', 'drupal.comment')), + ), + ); + $element['comment']['default_mode'] = array( + '#type' => 'checkbox', + '#title' => t('Threading'), + '#default_value' => $settings['default_mode'], + '#description' => t('Show comment replies in a threaded list.'), + ); + $element['comment']['per_page'] = array( + '#type' => 'select', + '#title' => t('Comments per page'), + '#default_value' => $settings['per_page'], + '#options' => _comment_per_page(), + ); + $element['comment']['anonymous'] = array( + '#type' => 'select', + '#title' => t('Anonymous commenting'), + '#default_value' => $settings['anonymous'], + '#options' => array( + COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'), + COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'), + COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'), + ), + '#access' => user_access('post comments', drupal_anonymous_user()), + ); + $element['comment']['subject'] = array( + '#type' => 'checkbox', + '#title' => t('Allow comment title'), + '#default_value' => $settings['subject'], + ); + $element['comment']['form_location'] = array( + '#type' => 'checkbox', + '#title' => t('Show reply form on the same page as comments'), + '#default_value' => $settings['form_location'], + ); + $element['comment']['preview'] = array( + '#type' => 'radios', + '#title' => t('Preview comment'), + '#default_value' => $settings['preview'], + '#options' => array( + DRUPAL_DISABLED => t('Disabled'), + DRUPAL_OPTIONAL => t('Optional'), + DRUPAL_REQUIRED => t('Required'), + ), + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function applyDefaultValue($notify = TRUE) { + $this->setValue($this->getInstance()->default_value, $notify); + return $this; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() { + // We always want the values saved so we can rely on them. + return FALSE; + } +} diff --git a/core/modules/comment/lib/Drupal/comment/Type/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Type/CommentItem.php deleted file mode 100644 index 642b5d3..0000000 --- a/core/modules/comment/lib/Drupal/comment/Type/CommentItem.php +++ /dev/null @@ -1,41 +0,0 @@ - 'integer', - 'label' => t('Comment status value'), - 'settings' => array('default_value' => COMMENT_OPEN), - ); - } - return static::$propertyDefinitions; - } - -}