Merge branch 'MDL-68796-master' of git://github.com/bmbrands/moodle
authorSara Arjona <sara@moodle.com>
Wed, 3 Jun 2020 12:25:37 +0000 (14:25 +0200)
committerSara Arjona <sara@moodle.com>
Wed, 3 Jun 2020 12:26:53 +0000 (14:26 +0200)
1  2 
contentbank/classes/output/bankcontent.php
contentbank/templates/bankcontent.mustache
contentbank/templates/bankcontent/toolbar.mustache
contentbank/tests/behat/view_preferences.feature
lang/en/contentbank.php

@@@ -97,57 -97,9 +97,58 @@@ class bankcontent implements renderable
                  'type' => $mimetype
              );
          }
+         $data->viewlist = get_user_preferences('core_contentbank_view_list');
          $data->contents = $contentdata;
 -        $data->tools = $this->toolbar;
 +        // The tools are displayed in the action bar on the index page.
 +        foreach ($this->toolbar as $tool) {
 +            // Customize the output of a tool, like dropdowns.
 +            $method = 'export_tool_'.$tool['action'];
 +            if (method_exists($this, $method)) {
 +                $this->$method($tool);
 +            }
 +            $data->tools[] = $tool;
 +        }
 +
          return $data;
      }
 +
 +    /**
 +     * Adds the content type items to display to the Add dropdown.
 +     *
 +     * Each content type is represented as an object with the properties:
 +     *     - name: the name of the content type.
 +     *     - baseurl: the base content type editor URL.
 +     *     - types: different types of the content type to display as dropdown items.
 +     *
 +     * @param array $tool Data for rendering the Add dropdown, including the editable content types.
 +     */
 +    private function export_tool_add(array &$tool) {
 +        $editabletypes = $tool['contenttypes'];
 +
 +        $addoptions = [];
 +        foreach ($editabletypes as $class => $type) {
 +            $contentype = new $class($this->context);
 +            // Get the creation options of each content type.
 +            $types = $contentype->get_contenttype_types();
 +            if ($types) {
 +                // Add a text describing the content type as first option. This will be displayed in the drop down to
 +                // separate the options for the different content types.
 +                $contentdesc = new stdClass();
 +                $contentdesc->typename = get_string('description', $contentype->get_contenttype_name());
 +                array_unshift($types, $contentdesc);
 +                // Context data for the template.
 +                $addcontenttype = new stdClass();
 +                // Content type name.
 +                $addcontenttype->name = $type;
 +                // Content type editor base URL.
 +                $tool['link']->param('plugin', $type);
 +                $addcontenttype->baseurl = $tool['link']->out();
 +                // Different types of the content type.
 +                $addcontenttype->types = $types;
 +                $addoptions[] = $addcontenttype;
 +            }
 +        }
 +
 +        $tool['contenttypes'] = $addoptions;
 +    }
  }
  }}
  
  {{#tools}}
 -    <a href="{{{ link }}}" class="icon-no-margin btn btn-secondary" title="{{{ name }}}">
 -        {{#pix}} {{{ icon }}} {{/pix}} {{{ name }}}
 -    </a>
 +    {{#dropdown}}
 +        {{>core_contentbank/bankcontent/toolbar_dropdown}}
 +    {{/dropdown}}
 +    {{^dropdown}}
 +        <a href="{{{ link }}}" class="icon-no-margin btn btn-secondary" title="{{{ name }}}">
 +            {{#pix}} {{{ icon }}} {{/pix}} {{{ name }}}
 +        </a>
 +    {{/dropdown}}
  {{/tools}}
- <button class="icon-no-margin btn btn-secondary active ml-2"
+ <button class="icon-no-margin btn btn-secondary {{^viewlist}}active{{/viewlist}} ml-2"
  title="{{#str}}  displayicons, contentbank  {{/str}}"
  data-action="viewgrid">
      {{#pix}}a/view_icon_active, core, {{#str}} displayicons, contentbank {{/str}} {{/pix}}
index 0000000,a5d9911..44fa8bf
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,28 +1,28 @@@
 -    When I click on "Display contentbank with file details" "button"
+ @core @core_contentbank @contentbank_h5p @javascript
+ Feature: Store the content bank view preference
+   In order to consistantly view the content bank in icons or details view
+   As an admin
+   I need to be able to store my view preference
+   Background:
+     Given the following "contentbank content" exist:
+         | contextlevel | reference | contenttype       | user  | contentname          |
+         | System       |           | contenttype_h5p   | admin | filltheblanks.h5p    |
+         | System       |           | contenttype_h5p   | admin | mathsbook.h5p        |
+   Scenario: Admins can order content in the content bank
+     Given I log in as "admin"
+     And I am on site homepage
+     And I turn editing mode on
+     And I add the "Navigation" block if not present
+     And I expand "Site pages" node
+     And I click on "Content bank" "link"
 -    And I click on "Display contentbank with icons" "button"
++    When I click on "Display content bank with file details" "button"
+     And I should see "Last modified"
+     And I follow "filltheblanks.h5p"
+     And I click on "Content bank" "link"
+     And I should see "Last modified"
++    And I click on "Display content bank with icons" "button"
+     And I follow "filltheblanks.h5p"
+     And I click on "Content bank" "link"
+     And I should not see "Last modified"
Simple merge