Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created June 3, 2016 11:22
Show Gist options
  • Save bangpound/83f37c74f9404f8e2800c34cbd19e221 to your computer and use it in GitHub Desktop.
Save bangpound/83f37c74f9404f8e2800c34cbd19e221 to your computer and use it in GitHub Desktop.
diff --git a/docroot/profiles/discoverdesign/modules/cafprojectedit/cafprojectedit.module b/docroot/profiles/discoverdesign/modules/cafprojectedit/cafprojectedit.module
index 80585de..2a67188 100644
--- a/docroot/profiles/discoverdesign/modules/cafprojectedit/cafprojectedit.module
+++ b/docroot/profiles/discoverdesign/modules/cafprojectedit/cafprojectedit.module
@@ -27,6 +27,7 @@ function cafprojectedit_preprocess_node(&$variables) {
/** @var \Drupal\node\Entity\Node $entity */
$entity = $variables['node'];
if ($entity->bundle() === 'project' && $entity->access('edit')) {
+ $variables['csrf'] = \Drupal::csrfToken()->get('rest');
$variables['editable'] = TRUE;
/** @var \Drupal\Core\Entity\EntityForm $form_object */
$form_object = \Drupal::entityTypeManager()->getFormObject('node', 'edit');
diff --git a/docroot/profiles/discoverdesign/themes/newel/templates/content/node--project--full.html.twig b/docroot/profiles/discoverdesign/themes/newel/templates/content/node--project--full.html.twig
index fd72ca9..3f6361c 100644
--- a/docroot/profiles/discoverdesign/themes/newel/templates/content/node--project--full.html.twig
+++ b/docroot/profiles/discoverdesign/themes/newel/templates/content/node--project--full.html.twig
@@ -70,8 +70,41 @@
* in different view modes.
*/
#}
+<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular-resource.js"></script>
+<script>
+ angular
+ .module('projectEdit',['ngResource'])
+ .constant('csrf', '{{ csrf }}')
+ .controller('EditController', ['$resource', '$http', 'csrf', function ($resource, $http, csrf) {
+ var Project = $resource('/node/226?_format=hal_json', {}, {
+ 'get': {method: 'GET'},
+ 'save': {
+ method: 'POST',
+ url: '/entity/node?_format=hal_json',
+ headers: {
+ 'X-CSRF-Token': csrf,
+ 'Content-type': 'application/hal+json'
+ },
+ transformRequest: function (data) {
+ // Drupal 8 refuses to let users edit some values which
+ // AngularJS GETs from it. We need to delete those and
+ // attend to the advice presented in:
+ // https://www.drupal.org/documentation/modules/rest/post
+ delete data.changed;
+ delete data.revision_timestamp;
+ delete data.revision_uid;
+
+ return angular.toJson(data);
+ }
+ }
+ });
+ this.project = Project.get({});
+ }]);
+</script>
+<article{{ attributes }} ng-app="projectEdit">
+ <div ng-controller="EditController as ec">
-<article{{ attributes }}>
{{ content.field_image }}
@@ -82,7 +115,7 @@
{{ content.field_icon }}
{# title_prefix #}
- <h2 class="step__title title-1">{% if editable %}{{ title_form }}{% else %}{{ label }}{% endif %}</h2>
+ <h2 class="step__title title-1">{% if editable %}<input ng-model="title.value" type="text" ng-repeat="title in ec.project.title"><button ng-click="ec.project.$save()">Save</button>{% else %}{{ label }}{% endif %}</h2>
{# title_suffix #}
<a href="{{ content.field_help_link[0]['#url'] }}" class="button dot use-ajax" data-dialog-type="modal" data-accepts="application/vnd.drupal-modal"><span class="visually-hidden">Need help</span>?</a>
@@ -113,5 +146,6 @@
{% endif %}
</footer>
+ </div>
</article>
diff --git a/styleguide b/styleguide
index bbe6c1a..b0a2a6a 160000
--- a/styleguide
+++ b/styleguide
@@ -1 +1 @@
-Subproject commit bbe6c1aabfaffd76a0d0f1a82742190718307a14
+Subproject commit b0a2a6a489e88da2dc3c0eabfb8b89602822e9f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment