Example #1
0
 /**
  * Add a GravityView menu to the Form Toolbar with connected views
  * @param  array  $menu_items Menu items, as set in GFForms::top_toolbar()
  * @param  int $id         ID of the current Gravity form
  * @return array            Modified array
  */
 static function gform_toolbar_menu($menu_items = array(), $id = NULL)
 {
     $connected_views = gravityview_get_connected_views($id);
     if (empty($connected_views)) {
         return $menu_items;
     }
     // This needs to be here to trigger Gravity Forms to use the submenu;
     // If there's only submenu item, it replaces the main menu link with the submenu item.
     $sub_menu_items = array(array('url' => '#', 'label' => '', 'menu_class' => 'hidden', 'capabilities' => ''));
     foreach ((array) $connected_views as $view) {
         $label = empty($view->post_title) ? sprintf(__('No Title (View #%d)', 'gravityview'), $view->ID) : $view->post_title;
         $sub_menu_items[] = array('url' => admin_url('post.php?action=edit&post=' . $view->ID), 'label' => esc_attr($label), 'capabilities' => current_user_can('edit_post', $view->ID));
     }
     $menu_items['gravityview'] = array('label' => __('Connected Views', 'gravityview'), 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', 'title' => __('GravityView Views using this form as a data source', 'gravityview'), 'url' => '#', 'onclick' => 'return false;', 'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', 'link_class' => 1 === 1 ? '' : 'gf_toolbar_disabled', 'sub_menu_items' => $sub_menu_items, 'capabilities' => array(), 'priority' => 0);
     return $menu_items;
 }
 /**
  * @since 1.15
  * @covers GravityView_Uninstall::fire_everything()
  */
 function test_fire_everything()
 {
     $create_count = 10;
     $form = $this->factory->form->create_and_get();
     $all_forms = GFAPI::get_forms();
     $views = $this->factory->view->create_many($create_count, array('form_id' => $form['id']));
     $entry_ids = $this->factory->entry->create_many($create_count, array('form_id' => $form['id']));
     $connected = gravityview_get_connected_views($form['id']);
     $entry_count = GFAPI::count_entries($form['id']);
     // Make sure the objects were created and connected
     $this->assertEquals($create_count, count(array_filter($views)));
     $this->assertEquals($create_count, count(array_filter($connected)));
     $this->assertEquals($create_count, count(array_filter($entry_ids)));
     $this->_set_up_expected_options();
     ### DO NOT DELETE WHEN THE USER DOESN'T HAVE THE CAPABILITY
     $user = $this->factory->user->create_and_set(array('user_login' => 'administrator', 'user_pass' => 'administrator', 'role' => 'administrator'));
     $this->assertTrue(GVCommon::has_cap('gravityview_uninstall'));
     ### DO NOT DELETE WHEN IT IS NOT SET OR SET TO FALSE
     // TRY deleting when the settings aren't configured.
     $this->_set_up_gravityview_settings(NULL);
     $this->uninstall();
     $this->_check_deleted_options(false);
     // TRY deleting when the Delete setting is set to No
     $this->_set_up_gravityview_settings('0');
     $this->uninstall();
     $this->_check_deleted_options(false);
     ### REALLY DELETE NOW
     // Create the items
     $this->_set_up_gravityview_settings('delete');
     $this->_set_up_notes($entry_ids);
     $this->_set_up_entry_meta($entry_ids, $form);
     $this->uninstall();
     // No Forms should be deleted
     $this->assertEquals($all_forms, GFAPI::get_forms());
     $this->_check_posts();
     $this->_check_entries($form, $entry_count);
     $this->_check_deleted_options();
     $this->_check_deleted_entry_notes($entry_ids);
     $this->_check_deleted_entry_meta($entry_ids);
 }
 /**
  * Should the Approve/Reject Entry column be shown in the GF Entries page?
  *
  * @since 1.7.2
  *
  * @param int $form_id The ID of the Gravity Forms form for which entries are being shown
  *
  * @return bool True: Show column; False: hide column
  */
 private function show_approve_entry_column($form_id)
 {
     $show_approve_column = GVCommon::has_cap('gravityview_moderate_entries');
     /**
      * @filter `gravityview/approve_entries/hide-if-no-connections` Return true to hide reject/approve if there are no connected Views
      * @since 1.7.2
      * @param boolean $hide_if_no_connections
      */
     $hide_if_no_connections = apply_filters('gravityview/approve_entries/hide-if-no-connections', false);
     if ($hide_if_no_connections) {
         $connected_views = gravityview_get_connected_views($form_id);
         if (empty($connected_views)) {
             $show_approve_column = false;
         }
     }
     /**
      * @filter `gravityview/approve_entries/show-column` Override whether the column is shown
      * @param boolean $show_approve_column Whether the column will be shown
      * @param int $form_id The ID of the Gravity Forms form for which entries are being shown
      */
     $show_approve_column = apply_filters('gravityview/approve_entries/show-column', $show_approve_column, $form_id);
     return $show_approve_column;
 }
 /**
  * Add a GravityView menu to the Form Toolbar with connected views
  * @param  array  $menu_items Menu items, as set in GFForms::top_toolbar()
  * @param  int $id         ID of the current Gravity form
  * @return array            Modified array
  */
 static function gform_toolbar_menu($menu_items = array(), $id = NULL)
 {
     $connected_views = gravityview_get_connected_views($id);
     if (empty($connected_views)) {
         return $menu_items;
     }
     $sub_menu_items = array();
     foreach ((array) $connected_views as $view) {
         if (!GVCommon::has_cap('edit_gravityview', $view->ID)) {
             continue;
         }
         $label = empty($view->post_title) ? sprintf(__('No Title (View #%d)', 'gravityview'), $view->ID) : $view->post_title;
         $sub_menu_items[] = array('label' => esc_attr($label), 'url' => admin_url('post.php?action=edit&post=' . $view->ID));
     }
     // If there were no items added, then let's create the parent menu
     if ($sub_menu_items) {
         // Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown
         $sub_menu_items[] = array('url' => '#', 'label' => '', 'menu_class' => 'hidden', 'capabilities' => '');
         $menu_items['gravityview'] = array('label' => __('Connected Views', 'gravityview'), 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', 'title' => __('GravityView Views using this form as a data source', 'gravityview'), 'url' => '#', 'onclick' => 'return false;', 'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', 'link_class' => 1 === 1 ? '' : 'gf_toolbar_disabled', 'sub_menu_items' => $sub_menu_items, 'priority' => 0, 'capabilities' => array('edit_gravityviews'));
     }
     return $menu_items;
 }