diff --git a/config/schema/flag.views.schema.yml b/config/schema/flag.views.schema.yml new file mode 100644 index 0000000..c832a5a --- /dev/null +++ b/config/schema/flag.views.schema.yml @@ -0,0 +1,5 @@ +# Schema for the views plugins of the flag module. + +views.filter.flag_filter: + type: views.filter.boolean + label: 'Flag filter' diff --git a/flag_bookmark/config/install/views.view.flag_bookmark.yml b/flag_bookmark/config/install/views.view.flag_bookmark.yml index 331c5f6..82b69ab 100644 --- a/flag_bookmark/config/install/views.view.flag_bookmark.yml +++ b/flag_bookmark/config/install/views.view.flag_bookmark.yml @@ -1,8 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - system.menu.main + module: + - flag + - node + - user +id: flag_bookmark +label: flag_bookmark +module: views +description: '' +tag: '' +base_table: node_field_data base_field: nid -base_table: node core: 8.x -description: '' -status: true display: default: display_plugin: default @@ -27,7 +39,7 @@ display: disable_sql_rewrite: false distinct: false slave: false - query_comment: false + query_comment: '' query_tags: { } provider: views dependencies: { } @@ -143,7 +155,7 @@ display: suffix: '' target: '' nl2br: false - max_length: '' + max_length: null word_boundary: true ellipsis: true more_link: false @@ -231,7 +243,7 @@ display: suffix: '' target: '' nl2br: false - max_length: '' + max_length: null word_boundary: true ellipsis: true more_link: false @@ -290,7 +302,7 @@ display: suffix: '' target: '' nl2br: false - max_length: '' + max_length: null word_boundary: true ellipsis: true more_link: false @@ -353,7 +365,7 @@ display: suffix: '' target: '' nl2br: false - max_length: '' + max_length: null word_boundary: true ellipsis: true more_link: false @@ -388,54 +400,6 @@ display: expose: operator: '' group: 1 - flagged: - id: flagged - table: flagging - field: flagged - relationship: flag_content_rel - group_type: group - admin_label: '' - dependencies: - module: - - flag - - flag - - flag - - flag - - flag - - flag - - flag - - flag - - flag - operator: '=' - value: '1' - group: 1 - exposed: false - expose: - operator_id: '' - label: '' - description: '' - use_operator: false - operator: '' - identifier: '' - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: { } - group_items: { } - plugin_id: flag_filter - provider: flag sorts: { } title: 'My Bookmarks' header: { } @@ -456,13 +420,13 @@ display: relationship: none group_type: group admin_label: Flags + required: true + flag: bookmark + user_scope: current dependencies: module: - flag - flag - required: false - flag: 'Stuff! custom' - user_scope: current plugin_id: flag_relationship provider: flag uid: @@ -479,6 +443,16 @@ display: plugin_id: standard provider: views arguments: { } + display_extenders: { } + cache_metadata: + max-age: 0 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } page_1: display_plugin: page id: page_1 @@ -494,13 +468,13 @@ display: name: main weight: 0 context: '0' -label: flag_bookmark -module: views -id: flag_bookmark -tag: '' -langcode: en -dependencies: - module: - - flag - - node - - user + display_extenders: { } + cache_metadata: + max-age: 0 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/flag_bookmark/flag_bookmark.info.yml b/flag_bookmark/flag_bookmark.info.yml index d5babcc..1ae0bed 100644 --- a/flag_bookmark/flag_bookmark.info.yml +++ b/flag_bookmark/flag_bookmark.info.yml @@ -4,4 +4,5 @@ core: 8.x type: module dependencies: - flag + - node package: Flags diff --git a/flag_bookmark/src/Tests/FlagBookmarkUITest.php b/flag_bookmark/src/Tests/FlagBookmarkUITest.php new file mode 100644 index 0000000..ddaa254 --- /dev/null +++ b/flag_bookmark/src/Tests/FlagBookmarkUITest.php @@ -0,0 +1,78 @@ +drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + + // Create a test user and log in. + $this->adminUser = $this->drupalCreateUser(array( + 'flag bookmark', + 'unflag bookmark', + 'create article content', + 'access content overview', + )); + $this->drupalLogin($this->adminUser); + } + + /** + * Test the flag_bookmark UI. + */ + public function testUi() { + + // Add articles. + $this->drupalPostForm('node/add/article', [ + 'title[0][value]' => 'Article 1', + ], t('Save')); + + // Check the link to bookmark exist. + $this->drupalGet('node/1'); + $this->assertLink(t('Bookmark this')); + + // Bookmark article. + $this->clickLink(t('Bookmark this')); + + // Check if the bookmark appears in the frontpage. + $this->drupalGet('node'); + $this->assertLink(t('Remove bookmark')); + + // Check the view is shown correctly. + $this->drupalGet('bookmarks'); + $xpath = $this->xpath('/html/body/div/main/div/div/div/div/div/table/tbody/tr/td[1]'); + $this->assertEqual($xpath[0]->a, 'Article'); + } + +} diff --git a/src/Plugin/views/filter/FlagViewsFilter.php b/src/Plugin/views/filter/FlagViewsFilter.php index 4d10b90..b159f5d 100644 --- a/src/Plugin/views/filter/FlagViewsFilter.php +++ b/src/Plugin/views/filter/FlagViewsFilter.php @@ -31,6 +31,8 @@ class FlagViewsFilter extends BooleanOperator { * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); + $form['value']['#type'] = 'radios'; $form['value']['#title'] = t('Status'); $form['value']['#options'] = [ @@ -39,12 +41,10 @@ class FlagViewsFilter extends BooleanOperator { // @todo Find out what in the hell filter type ALL is supposed to do. // 'All' => t('All'), ]; - $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value']; + $form['value']['#default_value'] = empty($this->options['value']) ? FALSE : $this->options['value']; $form['value']['#description'] = '

' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '

' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '

'; $form['relationship']['#default_value'] = $this->options['relationship']; - - parent::buildOptionsForm($form, $form_state); } /** @@ -58,4 +58,5 @@ class FlagViewsFilter extends BooleanOperator { $this->query->addWhere($this->options['group'], "$this->tableAlias.uid", NULL, $operator); } + }