0

I have a content type. Let us say "articles". When a user wants to create an article, the user will go to /node/add/article and it will show a form like it shows on stack exchange when go to /questions/ask.

What I want?

I want to create a block which will show the "create new node" form + my articles + articles of the user I am following with follow(user) flag. "My" and "user followed" articles should be shown below the form. The form and articles should always be visible in the block. When user saves a new article, it should show in the list below without page refresh.

The user should not be allowed to select text format. The admin should choose which text format to enable on this particular content type.

Note: When user visits node/add/articles directly, user must not see the articles. User should only see the form to create a new node.

I am sure I have explained it quite well. Let me know in case you have any questions.

1

I have a content type. Let us say "articles". When a user wants to create an article, he will go to /node/add/article and it will show a form like it shows on stack exchange when go to /questions/ask.

Give whichever user you want to create the node, permission to do so /admin/people/permissions

What I want?

I want to create a block which will show the "create new node" form as above

  • my articles

You mean the articles of admin or of the user creating the form? If admin, create a view with articles and filter by user admin, or filter by currently logged in user.

  • articles of the user I am following with follow(user) flag.

as above. I presume you are giving the user the ability to flag other users to follow somehow? So you could filter by a list of users that are being followed.

"My" and "user followed" articles should be shown below the form. The form and articles should always be visible in the block.

When user saves a new article, it should show in the list below without page refresh.

You would use ajax to achieve this. Check out 'exposed filters' in views and look for the option to 'use ajax'.

The user should not be allowed to select text format. The admin should choose which text format to enable on this particular content type.

This is built in. There are permissions for, example, "Use the Filtered HTML text format" and in the settings for the content type, which text formats are available.

Note: When user visits node/add/articles directly, he must not see the articles. He should only see the form to create a new node.

I am sure I have explained it quite well. Let me know in case you have any questions.

There are multiple questions here, and ideally you would post some code and show what you have already done.

  • I think you have taken my question wrong alltogether. I would recommend reading it again. Do not divide my question unnecessarily to too many sub-questions. – Umair Jan 4 '17 at 16:33
  • Okay. Please only answer this What I want? I want to create a block which will show the "create new node" form + current user articles + articles of the user (the current user is following). "My" + "user followed" articles should be shown below the "form". The form and articles should always be visible in the block. All this should show in one block. Note: When user visits node/add/articles directly, he must not see the articles. He should only see the form to create a new node. – Umair Jan 4 '17 at 16:35
  • Hope I am clear this time. Think of twitter user dashboard. There is a "form" to create a tweet and below that form, current user tweets + tweets from the users (current user is following), are shown. – Umair Jan 4 '17 at 16:39
  • 1
    As fair as I understand this site is to give feedback on code, and in some cases specific design questions. What you have written is basically pseudo-code. Go away and try some stuff. – Andrew Welch Jan 5 '17 at 10:03
  • Now what Andrew? – Umair Jan 10 '17 at 15:13
0

I almost got it working. I have found a module, formblock, which enables the presentation of user registration, site wide contact, or node creation forms in blocks. That was one part. Now How I created current user articles + articles of the user (the current user is following)? I have added the export of view. I also enabled ajax.

I generated a block using form block module and then in the header of the view, I added Global: Block area and selected the block generated by the module. Now it is showing the a form above the view.

There are few to dos.

  1. When I create an article and send it, it redirects me to the individual node page. For example: site.com/node/1. How to solve it?

  2. I want to use filtered html on this content type, but do not want users to make the choice. Currently, there is a dropdown showing which enables users to choose which text format to use to create an article.

Exported View

$view = new view();
$view->name = 'contextual';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Contextual';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Contextual';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'input_required';
$handler->display->display_options['exposed_form']['options']['text_input_required_format'] = 'filtered_html';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'picture' => 'picture',
  'name' => 'name',
  'title' => 'title',
  'comments_link' => 'comments_link',
  'delete_node' => 'delete_node',
  'edit_node' => 'edit_node',
  'created' => 'created',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'picture' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-left',
    'separator' => '',
    'empty_column' => 0,
  ),
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-left',
    'separator' => '',
    'empty_column' => 0,
  ),
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-center',
    'separator' => '',
    'empty_column' => 0,
  ),
  'comments_link' => array(
    'align' => 'views-align-left',
    'separator' => '',
    'empty_column' => 0,
  ),
  'delete_node' => array(
    'align' => 'views-align-right',
    'separator' => '',
    'empty_column' => 0,
  ),
  'edit_node' => array(
    'align' => 'views-align-right',
    'separator' => '',
    'empty_column' => 0,
  ),
  'created' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-center',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Header: Global: Block area */
$handler->display->display_options['header']['block']['id'] = 'block';
$handler->display->display_options['header']['block']['table'] = 'views';
$handler->display->display_options['header']['block']['field'] = 'block';
$handler->display->display_options['header']['block']['empty'] = TRUE;
$handler->display->display_options['header']['block']['block_to_insert'] = 'formblock:article';
$handler->display->display_options['header']['block']['title'] = '<none>';
/* Relationship: User: Content authored */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'users';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* Relationship: Flags: follow */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'users';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'follow';
/* Field: User: Picture */
$handler->display->display_options['fields']['picture']['id'] = 'picture';
$handler->display->display_options['fields']['picture']['table'] = 'users';
$handler->display->display_options['fields']['picture']['field'] = 'picture';
$handler->display->display_options['fields']['picture']['label'] = '';
$handler->display->display_options['fields']['picture']['element_label_colon'] = FALSE;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'uid';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Delete link */
$handler->display->display_options['fields']['delete_node']['id'] = 'delete_node';
$handler->display->display_options['fields']['delete_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['delete_node']['field'] = 'delete_node';
$handler->display->display_options['fields']['delete_node']['relationship'] = 'uid';
$handler->display->display_options['fields']['delete_node']['label'] = '';
$handler->display->display_options['fields']['delete_node']['element_label_colon'] = FALSE;
/* Field: Content: Edit link */
$handler->display->display_options['fields']['edit_node']['id'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['edit_node']['field'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['relationship'] = 'uid';
$handler->display->display_options['fields']['edit_node']['label'] = '';
$handler->display->display_options['fields']['edit_node']['element_label_colon'] = FALSE;
/* Field: Content: Post date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['relationship'] = 'uid';
$handler->display->display_options['fields']['created']['label'] = '';
$handler->display->display_options['fields']['created']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created']['date_format'] = 'time ago';
$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
/* Field: Content: Add comment link */
$handler->display->display_options['fields']['comments_link']['id'] = 'comments_link';
$handler->display->display_options['fields']['comments_link']['table'] = 'node';
$handler->display->display_options['fields']['comments_link']['field'] = 'comments_link';
$handler->display->display_options['fields']['comments_link']['relationship'] = 'uid';
$handler->display->display_options['fields']['comments_link']['label'] = '';
$handler->display->display_options['fields']['comments_link']['alter']['text'] = '<a href="[comments_link]">Reply</a>';
$handler->display->display_options['fields']['comments_link']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['comments_link']['teaser'] = TRUE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['relationship'] = 'uid';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
$handler->display->display_options['filter_groups']['groups'] = array(
  1 => 'OR',
);
/* Filter criterion: User: Current */
$handler->display->display_options['filters']['uid_current']['id'] = 'uid_current';
$handler->display->display_options['filters']['uid_current']['table'] = 'users';
$handler->display->display_options['filters']['uid_current']['field'] = 'uid_current';
$handler->display->display_options['filters']['uid_current']['value'] = '1';
$handler->display->display_options['filters']['uid_current']['group'] = 1;
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flagging';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '1';
$handler->display->display_options['filters']['flagged']['group'] = 1;

/* Display: CurOrArg */
$handler = $view->new_display('block', 'CurOrArg', 'block_1');
  • ask separate questions please and please check existing answers. – Andrew Welch Jan 10 '17 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.