<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Charlotte Bone on Medium]]></title>
        <description><![CDATA[Stories by Charlotte Bone on Medium]]></description>
        <link>https://medium.com/@charlotte.bone?source=rss-b4e1b5aac7cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*UrgKi0Z-dMW3MCy6dTKZvA.jpeg</url>
            <title>Stories by Charlotte Bone on Medium</title>
            <link>https://medium.com/@charlotte.bone?source=rss-b4e1b5aac7cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 02:09:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charlotte.bone/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How And When To Use Git Reset]]></title>
            <link>https://medium.com/charlottes-digital-web/how-and-when-to-use-git-reset-ec8088e0c811?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec8088e0c811</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[git-reset]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Tue, 26 Nov 2019 23:14:14 GMT</pubDate>
            <atom:updated>2019-11-27T22:33:27.247Z</atom:updated>
            <content:encoded><![CDATA[<h4>Most of us avoid dreaded git reset command — but actually it can be really useful, as long as you know how it works!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CoduaiVlxXB-by-ciZV_PA.png" /></figure><h3>What does git reset do?</h3><p>To put it simply, git reset will take your branch back to a certain point in the commit history, but there are 3 different levels to this:</p><ul><li><strong>soft</strong>: Moves the <strong>head</strong> back to the commit specified but leaves all the updated files in the index and working directory —<em>all of the files after the commit that you’ve moved to have been tracked (like doing git add) and are ready to be committed as a new commit.</em></li><li><strong>mixed</strong>: Moves the <strong>head</strong> and <strong>index </strong>back to the commit specified but leaves the files in the working directory — <em>all of the files after the commit are in your working file as untracked folder. If you add them all now, you’ll be at the same stage as a soft reset above.</em></li><li><strong>hard</strong>: Moves the <strong>head, index and working </strong>directory back to the commit specified — <em>all of the updated files after the commit specified are now </em><strong><em>GONE</em></strong><em>!!! (uncommitted files are unrecoverable at this point)</em></li></ul><h3>Why would you need this?</h3><p>Here are a few examples so that you will have a better idea of when to use each. You should only ever do this on your own branch, or when you’re sure no one has already pulled any of the commits that you will be removing.</p><h4>Soft</h4><p>Let’s say you have done a few tiny commits and you want them to all be put into 1 more descriptive commit.</p><p>A -&gt; B -&gt; C -&gt; D</p><pre>git reset — soft A</pre><p>Your branch head is now pointing at A</p><pre>git commit -m “my new merged commit”<br>git push origin branch --force-with-lease</pre><p>We now have a new commit, E but it contains all of the files that were committed in B, C, D. <em>Note: the </em>force-with-lease<em> flag is because otherwise git will complain that your local branch is behind the remote, this is a safer version of force</em></p><p>A-&gt;E</p><h4>Mixed</h4><p>You’ve just pushed a few commits, but you want to go back and remove a couple of files in a previous commit.</p><p>A-&gt;B-&gt;C</p><pre>git reset --mixed A</pre><p>Your branch head and index is pointing at A</p><pre>git status</pre><p>This will show that all of your changes in B and C are there, but are untracked</p><p>Now you are free to add the files that you wish to add into a new commit</p><pre>git add &lt;files&gt;<br>git commit -m &quot;updated commit&quot;<br>git push origin branch --force-with-lease</pre><p>A-&gt;D</p><p>Your head is now at the new commit D, and any files that you’ve not staged will still be in your working tree, ready to add into another commit or to do what you want with.</p><h4>Hard</h4><p>When would you possibly want this? Usually when things have gone wrong because it’s VERY RISKY. I’ll talk you through a scenario where I’ve needed it.</p><p>I’ve been working on my own branch, testing out a feature and I’ve changed many files, but it’s been a fail and I want to go back a few commits and get rid of every change I’ve made since.</p><p>If I’ve not made any commits or haven’t pushed any commits. I can just reset back to commit A and my working directory is now clear, all of my updated files are gone from history.</p><pre>git reset --hard A</pre><p>If I’ve actually pushed these commits to my remote branch, then, before doing this, you need to <strong>make sure that no one is working from those commits</strong> because they will be orphaned. But if you know that it’s safe to do, then run the command above. The only difference here is that you will need to do a FORCED push afterwards to push the remote branch to that state, otherwise it will tell you that your local branch is behind.</p><pre>git reset --hard A<br>git push origin branchname --force-with-lease</pre><p>This will delete your commits from the remote branch history, so you can see it could be very dangerous.</p><p>I have used this to get me out of reverted merge commit hell recently. I did a pull request to merge a branch into another branch, it had merge conflicts and the conflicts were not resolved correctly, so I reverted the merge. This however meant I couldn’t do the pull request again because it saw no updates, so I tried to revert that and it ended up in a bit of a mess. I then used git reset — force to take the branches back to before this situation and get rid of these ugly reverts in the history!</p><h4>Hopefully now you will see that git reset is very powerful and can help you in some situations, used with care!</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec8088e0c811" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/how-and-when-to-use-git-reset-ec8088e0c811">How And When To Use Git Reset</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling CORS On A Magento 2 Site Using An Nginx Server]]></title>
            <link>https://medium.com/charlottes-digital-web/enabling-cors-on-a-magento-2-site-using-an-nginx-server-481c8931f8b2?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/481c8931f8b2</guid>
            <category><![CDATA[magento-2]]></category>
            <category><![CDATA[magento]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[headless]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Sun, 17 Nov 2019 21:27:21 GMT</pubDate>
            <atom:updated>2019-11-17T21:27:21.986Z</atom:updated>
            <content:encoded><![CDATA[<p>After spending a while fighting CORS issues using a headless Magento 2 setup, here is how I solved the issue using nginx.conf</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qCeW_vtmvdgiULvifVIGg.png" /><figcaption>CORS error messages in Chrome console</figcaption></figure><p>Before jumping into a solution, I think it’s important to understand what is happening and why</p><h3>What is CORS?</h3><p>CORS stands for Cross-Origin Resource Sharing and it basically controls which sites can access the resources of another site. If you are running applications on different subdomains and/or domains and they need to talk to each other, then you will need to setup CORS.</p><h3>How do we setup CORS?</h3><p>You will need to send specific headers from the application that is being accessed. So for example, if your front end application is on one domain and it needs to access an API on another domain, you must setup the access headers on the API server.</p><h3>Docker Setup</h3><p>This tutorial is only for a server running Nginx. If you already have Magento up and running and you just want to look at the final configuration file settings then you can skip this section.</p><p>For my setup I user docker compose using <a href="https://github.com/markshust/docker-magento">Mark Shust’s configuration</a> and <a href="https://devdocs.magento.com/guides/v2.3/install-gde/composer.html">Magento community edition is installed via composer</a>. By default the docker-compose.dev.yml will mount the default Magento nginx.conf.sample file as your default configuration file. As we need a custom configuration file, copy the contents of <strong>nginx.conf.sample</strong> into a <strong>nginx.conf </strong>file in your root Magento folder. Update <strong>docker-compose.dev.yml</strong> replacing</p><pre>./src/nginx.conf.sample:/var/www/html/nginx.conf:delegated</pre><p>With</p><pre>./src/nginx.conf:/var/www/html/nginx.conf:delegated</pre><p>Now this will be the configuration file that will be used on the nginx server.</p><h3>Nginx Configuration Settings</h3><h4>CORS Preflight Request</h4><p>When a site tries to request access to resources from another site, it will first of all send a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request">preflight request</a>. This basically just asks the server if it will allow the request and it’s sent in the form of an OPTIONS request. This is why if you sent a POST request to another server, you will also see an OPTIONS request sent first.</p><p>So, we need to make sure that when an OPTIONS request is sent to our Nginx server, that we respond back with the correct headers. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1b9ead77af40a720038b591e17c38a8/href">https://medium.com/media/a1b9ead77af40a720038b591e17c38a8/href</a></iframe><ul><li><strong>Access-Control-Allow-Origin:</strong> the domain allowed, * allows ALL domains. You cannot put multiple domains here (how to restrict to multiple domains is explained further down)</li><li><strong>Access-Control-Allow-Methods:</strong> the methods to allow CORS requests for. You might need PUT and DELETE too if you’re using the REST API, as I’m using GraphQL, I’m only using POST, GET and OPTIONS.</li><li><strong>Access-Control-Allow-Headers:</strong> the allowed request headers. If you were for example to send an Authorization header without it being listed here then your request will be rejected.</li><li><strong>Access-Control-Allow-Credentials:</strong> I’ve not included this in my configuration but I want to explain what this does. It will allow cookies to be sent with the request, for example if you need to authorise using a session cookie.</li></ul><p><strong>Where do we put this code?</strong></p><p>You’ll notice entry points within the nginx.conf file. Most of the time you would put it in the root location, however in the Magento setup, this won’t work.</p><pre>location / {</pre><pre>  try_files $uri $uri/ /index.php$is_args$args<em>;</em></pre><pre>}</pre><p>This is because it uses <strong>try_files</strong> and if you set the headers above this then they get ignored because it checks for the index.php file and redirects if it exists. So you need to find the entry point for php files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aa9d8e569f280236b379aa0e33f089f/href">https://medium.com/media/8aa9d8e569f280236b379aa0e33f089f/href</a></iframe><p>You’ll notice that I’ve set the cors origin url in a variable, this is because we also need to set the <strong>Access-Control-Allow-Origin</strong> outside of the OPTIONS request block, for all other requests. This has to be repeated because if you set headers in an if block, it overwrites the previous add_header statements, see <a href="https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/">if is evil</a> for an explanation.</p><p>If you restart nginx (bin/restart if you’re using the same docker configuration as me) then you’ll now be able to do CORS requests. However, it’s not very secure as it’s using <strong>*</strong> so it’s accessible to any domain! let’s restrict that!</p><h3>Restricting CORS to certain domains</h3><p>As I mentioned above, sadly we can’t use multiple domains within the Access-Control-Allow-Origin header. So we have to do the logic outside of the header setting. Thankfully this is possible with simple regex:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dc6b92508097a5d07f49c1d1ede6a2f/href">https://medium.com/media/9dc6b92508097a5d07f49c1d1ede6a2f/href</a></iframe><p>Here, we’re simply setting the $cors_origin to the current request origin if it matches either <a href="https://localhost:8000/">https://localhost:8000</a> or <a href="https://mywebsite.com./">https://mywebsite.com.</a> You can modify this to allow multiple domains and subdomains.</p><p>Putting all of that together, here is my php entry point (<strong><em>note: the configuration below the final add_header is the default magento configuration and may change with updates, so please do not just copy and paste everything</em></strong>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e5f18970a0a28e45bddf748401af8ad/href">https://medium.com/media/3e5f18970a0a28e45bddf748401af8ad/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=481c8931f8b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/enabling-cors-on-a-magento-2-site-using-an-nginx-server-481c8931f8b2">Enabling CORS On A Magento 2 Site Using An Nginx Server</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Redux in Next.js with Hybrid Static/Server Rendered Applications]]></title>
            <link>https://medium.com/charlottes-digital-web/using-redux-in-next-js-with-hybrid-static-server-rendered-applications-a9939a94246a?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9939a94246a</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[static-site-generator]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 12:12:44 GMT</pubDate>
            <atom:updated>2019-10-18T12:12:44.097Z</atom:updated>
            <content:encoded><![CDATA[<h4>Next.js 9 brought in automatic partial static export that automatically determines if pages can be rendered statically. To make the most of this, you can’t use the widely used Redux wrapper so here is how you can setup without this.</h4><p>I should mention before you start this tutorial that the <a href="https://github.com/kirill-konshin/next-redux-wrapper#automatic-partial-static-export">Redux wrapper</a> was created for a specific purpose, so that actions are consistently dispatched on all pages on client and on server. So if you need that functionality, then you should continue to use it. This tutorial is for sites that always dispatch on the client side.</p><p>Why would you need a hybrid application? This was the case for me because I had a Shopify application with the server dealing with initially authorising my application and any AJAX API requests.</p><p>So the most important thing to make sure that your pages can be statically rendered is to remove any calls to <strong>getInitialProps </strong>in all pages. Before I switched to Next.js 9, I had used this in pages to get query parameters. Here is how you can get query parameters using <strong>useRouter</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d29928b8effb4bd6014fa8898a970a44/href">https://medium.com/media/d29928b8effb4bd6014fa8898a970a44/href</a></iframe><p>Ok, now onto our _app.js file. This is the example given for using the Redux wrapper. You’ll have a createStore function, default state, reducer and actions. Really you should have these all neatly in separate folders and files. But here I’ll just work from the example and show how you would change them around to work without this wrapper.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12125959bb10b67c8f925e42df8d365b/href">https://medium.com/media/12125959bb10b67c8f925e42df8d365b/href</a></iframe><p>Firstly, make sure that you have redux and react-redux installed and saved into your project dependencies.</p><pre>npm install — save redux react-redux </pre><p>Using the example above, we can remove the withRedux import, remove the whole getInitialProps section and add in the store variable. I removed the reducer too and put it in a separate file.</p><pre>store = makeStore()</pre><p>Then we remove the export default withRedux statement at the end and simply export our app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0176f6789f0d9b1e8acbd4d9eddc83f/href">https://medium.com/media/b0176f6789f0d9b1e8acbd4d9eddc83f/href</a></iframe><p>Here is the reducers file, I’ve changed it from the FOO example to a simple modal example so that it makes a little more sense.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a31faa929e123782f59e192891dd009/href">https://medium.com/media/2a31faa929e123782f59e192891dd009/href</a></iframe><p>Now we’ve removed the wrapper, it means that we have to deal with connecting components using the <a href="https://react-redux.js.org/api/connect">Redux connect function</a>, as we would with any other React project. I’m not going into depth with how Redux works here as this tutorial is assuming that you already understand the concepts, but it accepts 4 parameters:</p><ol><li><strong>mapStateToProps</strong> — this is used to pass the state as props down to the component. You either supply a function or you pass null or undefined if you do not wish it to subscribe to store updates. One thing to note is that even though you might be used to using the spread operator,<a href="https://react-redux.js.org/using-react-redux/connect-mapstate#only-return-new-object-references-if-needed"> you should only return new objects if needed to avoid unnecessary re-renders</a></li><li><strong>mapDispatchToProps</strong> — this is used create props that will map to dispatch actions to update the state.</li><li><strong>mergeProps </strong>— this isn’t used that often, if you leave it blank it will combine the components ownProps, mapStateToProps and mapDispatchToProps. If you want to be more specific with the props returned you can pass a function. <a href="http://enthudrives.com/blog/connect-with-mergeprops/">There is a great post here explaining why mergeProps may be useful</a>.</li></ol><p>It’s normally the best practice to create a container element that will pass the state to the child props rather than connecting every component. For this I’m going to show a very simple modal component example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d81aa5dec529db73d5271b855157073/href">https://medium.com/media/5d81aa5dec529db73d5271b855157073/href</a></iframe><p>Here is the actions file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41ca9b618a451a4b4459b6720cb6d445/href">https://medium.com/media/41ca9b618a451a4b4459b6720cb6d445/href</a></iframe><p>Now when you run <strong>next build </strong>(usually triggered with <strong>npm run build</strong>, depending on your setup)<strong> </strong>you will see that if you’ve successfully removed all calls to getInitialProps that pages are generated as static pages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*mI3GI9m7foq94CnsNm1ANA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9939a94246a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/using-redux-in-next-js-with-hybrid-static-server-rendered-applications-a9939a94246a">Using Redux in Next.js with Hybrid Static/Server Rendered Applications</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Most Common Web Accessibility Mistakes & How To Solve Them]]></title>
            <link>https://medium.com/charlottes-digital-web/the-most-common-web-accessibility-mistakes-how-to-solve-them-5b7d25a337e0?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b7d25a337e0</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[web-accessibility]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 11:54:01 GMT</pubDate>
            <atom:updated>2019-10-16T12:12:30.621Z</atom:updated>
            <content:encoded><![CDATA[<h4>Sadly, accessibility is not often given the priority that it should be. It’s harder to make a website accessible at the end of development than during development.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Yma0jdh7XKasy5MLSlfHw.jpeg" /><figcaption>Photo by Simon Gray from <a href="https://www.freeimages.com/">Free Images</a></figcaption></figure><p>Accessibility is so important and unfortunately, it’s not often seen as a priority in companies unless a client requires it, e.g. for government sites. The fact is that all sites should be inclusive and <a href="https://www.3playmedia.com/2019/06/12/2018sweb-accessibility-lawsuits/">you could even find yourself facing a large fine if a disabled user is unable to access your services</a>.</p><p><a href="https://www.w3.org/">The World Wide Web Consortium (W3C)</a> has a set of <a href="https://www.w3.org/TR/WCAG21/">Web content accessibility guidelines</a> with 3 levels of conformance: A (lowest), AA, and AAA (highest). AAA is quite difficult to achieve, however I’d always recommend aiming for the highest, so then your site should end up at least AA, which is required by most government sites.</p><p>It’s also important to note that these guidelines are not just for developers, a lot of consideration needs to be taken at the design stage when choosing colours, font sizes, etc too. Here are a list of things that I’ve noticed come up a lot during development and how you should think about doing them in future. It’s by no means a full list though, so please still <a href="https://www.w3.org/TR/WCAG21/">familiarise yourself with the guidelines</a>.</p><h3>Removing focus styles</h3><p>This is a HUGE mistake that people make. We all know that the default focus styles can really ruin a design, but they are there for a reason. Some users are not about to use a mouse due to disabilities, so they need to use a keyboard to navigate through your site. If you remove these styles then they will not know what action that they are about to perform.</p><p>So how can we maintain accessibility and aesthetics? <strong>:focus-visible</strong> is a pseudo class created, similar to <strong>:focus</strong> that is meant to solve the issue of focus styles also being visible when a user clicks with a mouse. Sadly <a href="https://caniuse.com/#search=%3Afocus-visible">it’s not widely available on browsers yet</a> as it’s part of the <a href="https://www.w3.org/TR/selectors-4/#the-focus-visible-pseudo">CSS4 working draft</a>.</p><p>I personally use the <a href="https://www.npmjs.com/package/focus-visible">focus-visible polyfill</a>. I am then able to turn off default focus styles:</p><pre><em>:focus</em>{ <br>  outline: none;<br>}</pre><p>Then I can style every element that requires a focus separately, or all elements using the new .focus-visible class that the polyfill adds. For example:</p><pre><em>.focus-visible</em>{<br>  outline: 1px solid $brilliant-rose;<br>}</pre><p>or styling a specific element:</p><pre>.top-link{<br>  border-bottom: 1px solid transparent;</pre><pre>  &amp;<em>.focus-visible</em>{<br>    outline: none;<br>    border-bottom: 1px solid $brilliant-rose;<br>  }<br>}</pre><h3>Not making elements tabbable</h3><p>It’s all very well styling the focus but we need to make sure that users are actually able to tab to elements that have an action. This is where it’s important to select the correct HTML element to use. Both anchor links and buttons are automatically tabbable, however the button is also triggered using the space bar. The general rule I use is:</p><ul><li>Buttons — use when triggering an action on the page, such as a javascript action like opening a menu, or submitting a form</li><li>Anchors — use these to take a user to another page or another part of the page</li></ul><p>If you use other elements such as a div then you will have to add in both a tabindex attribute AND ensure that the event is called on enter. For example:</p><pre>&lt;div tabindex=&quot;0&quot;&gt;Test Element&lt;/div&gt;</pre><p>Would make the element tabbable in the order that it appears in the DOM, but if you have an onClick action then the user will not be able to hit enter. There are multiple ways of doing this, for example if you use React</p><pre>&lt;div tabindex=&quot;0&quot; onKeyPress={keyPress}&gt;Test Element&lt;/div&gt;</pre><p>The even then checks for the enter key</p><pre>keyPress(<strong>event</strong>){<br>  <strong>if</strong> (<strong>event</strong>.key === &quot;Enter&quot;) {<br>    //action here<br>  } <br>}</pre><p>There are very few scenarios I’ve come across where this would be needed over a button.</p><p>One gotcha I’ve recently had come up too is that an anchor without a href value is not tabbable. This was due to a library I used to scroll to another part of the page. You can add in a # as a fix but really you should consider if it’s actually more suited to a button element if it’s only using javascript. There’s no definite answer here.</p><h3>Having an illogical tab order</h3><p>Sometimes, especially when using content management systems (CMS), the markup may be added in an usual order. The styling is then done in such a way that it looks fine, but when you tab, the order is incorrect. Really you should always try to put elements in order, but if you are in this situation then you will manually have to use the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex">tabindex</a> attribute to set your order.</p><h3>Not hiding tabbable elements correctly</h3><p>Another important thing to remember is that just because an item is hidden from view, it doesn’t always mean that it can’t be tabbed to. This is the case if you are using CSS attributes such as opacity: 0. The element is technically still able to be focused on and this can be really confusing if you’re a keyboard only user. <strong>Make sure that you use display: none or visibility: hidden </strong>which will stop users being able to focus on that element. If this affects an animation then a trick you can use is to apply the style after the animation.</p><h3>Using icons as buttons</h3><p>This is something that we see on pretty much every site nowadays. The problem is that a lot of sites are not considering screen readers users as they won’t have a description of this icon. Some people add in a title attribute to links or buttons, but <strong>you should not be relying on title attributes for accessibility</strong>. Unfortunately it’s not consistent across devices, browsers and screen reader software. Even <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute">aria-label</a> should not be relied upon.</p><p>The easiest way is to add in some text that is hidden off the screen and will only be read out by screen readers. There are a few ways to do this, here is one example. <strong>Do not use display:none</strong> because then it will not be read out either.</p><pre><em>.visually-hidden</em>{<br>  clip-path: inset(100%);<br>  clip: rect(1px 1px 1px 1px); <em>/* IE 6/7 */<br>  </em>clip: rect(1px, 1px, 1px, 1px);<br>  height: 1px;<br>  overflow: hidden;<br>  position: absolute;<br>  white-space: nowrap;<br>  width: 1px;<br>}</pre><p>An example of this in use</p><pre>&lt;button&gt;<br>  &lt;i class=&quot;fa-times&quot;&gt;&lt;/i&gt;<br>  &lt;span class=&quot;visually-hidden&quot;&gt;Close Menu&lt;/span&gt;<br>&lt;/button&gt;</pre><p>I personally have started using inline svg icons over font icons. <a href="https://www.w3.org/TR/SVG11/struct.html#DescriptionAndTitleElements">Inline SVGs can have a &lt;title&gt; and a &lt;desc&gt; tag</a>, so if you are able to add those within the SVG then you do not need to add extra text that is visually hidden. The same is the case if you use <a href="https://www.w3.org/WAI/tutorials/images/functional/">functional &lt;img&gt; elements</a>, you can use the alt attribute.</p><p>One scenario I’ve come across too is that I had a reusable inline SVG that required different descriptions. In this case I used <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-hidden_attribute">aria-hidden</a> attribute on the SVG element and used the visually hidden text as a description. It’s important not to confuse screen reader users with multiple descriptions.</p><p><em>There is also the case that maybe we should be adding more text for all users. I’ve read a few articles on here suggesting that actually icons alone aren’t very user friendly.</em></p><h3>Using unsuitable link text</h3><p>Imagine that you are a screen reader user and you’re tabbing through a long list of links. “Click here” or “read more” for every link isn’t very informative is it? <strong>We need to ensure that link text is descriptive on its own.</strong></p><p>There are scenarios where it would look really bad to add long descriptive text. I’ve worked on a site that listed events using a CMS and we had a book tickets link next to each event. It would have really ruined the look of the site to add the whole event description onto the link that was styled like a button.</p><p>This is where visually hidden text comes into play again. We can add an extended description for screen reader users without ruining the aesthetics of the site.</p><pre>&lt;button&gt;<br>  &lt;span&gt;Book Tickets&lt;/span&gt;<br>  &lt;span class=&quot;visually-hidden&quot;&gt; for X event on the DD of MM YYYY&lt;/span&gt;<br>&lt;/button&gt;</pre><h3>Make accessibility testing part of your standard testing!</h3><p>As you can see, these are very simple little things to do at the time of developing, but if you had to go back through a website and add these in, it would take a long time. Make this part of your standard process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b7d25a337e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/the-most-common-web-accessibility-mistakes-how-to-solve-them-5b7d25a337e0">The Most Common Web Accessibility Mistakes &amp; How To Solve Them</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto deploy a Node app to the Google App Engine]]></title>
            <link>https://medium.com/charlottes-digital-web/auto-deploy-node-app-to-google-app-engine-bad2a17f2526?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bad2a17f2526</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[google-app-engine]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 11:41:38 GMT</pubDate>
            <atom:updated>2019-10-12T15:42:07.514Z</atom:updated>
            <content:encoded><![CDATA[<p>I have built a Shopify admin application using Node.js and Next.js and I have been looking at the best places to host it. I originally used <a href="http://heroku.com/">Heruko</a> which is super simple and requires barely any setup. However, the free tier is not very reliable and I didn’t want to pay for upgraded plans before I know if the application will be successful. After doing some research, I found out that <a href="https://cloud.google.com/free/docs/gcp-free-tier#always-free-usage-limits">Google App Engine</a> offers a really good free option as long as you stay within the limits. I’ve got experience with AWS and I have always wanted to give Google cloud a try so here is what I learnt.</p><p>Firstly, you’ll need to <a href="https://cloud.google.com/free/">sign up here</a>, you can see that they offer $300 credit for the first year if you have an application that needs to use more resources. Then once you’ve signed up, you’ll need to create a new application. The free tier is only available for the standard environment, so make sure to select that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PrL6kOKt48iTsuUrTN4LiA.png" /></figure><p>Google cloud does have <a href="https://cloud.google.com/sdk/docs/quickstarts">an SDK</a> that allows you to deploy via the command line. This is what I used to start with but I’m used to having everything automated so I didn’t really want to have to manually run a command every time. So this tutorial will show you how to link to a repository and trigger builds after a push to the master branch (or any other branch).</p><p>There are a few files that you need to setup within your main project folder.</p><ol><li><strong>app.yaml</strong></li></ol><p>For a simple setup, you won’t need much in this file. The only thing that you must add is the runtime, which is responsible for installing your code &amp; dependencies. You can also add environment variables here, but I should stress that <strong>these shouldn’t contain sensitive data</strong> because it will be committed into your repository. By default your NODE_ENV will be set to production. Here is <a href="https://cloud.google.com/appengine/docs/standard/nodejs/config/appref">the link to the documentation</a> and here is a bare minimum setup file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80504c6adf75cdad82084794f03428d0/href">https://medium.com/media/80504c6adf75cdad82084794f03428d0/href</a></iframe><p>2. <strong>cloudbuild.yaml</strong></p><p>This defines the build configuration. If you’ve ever used bitbucket pipelines, it’s pretty similar to that. You add the name of the <a href="https://cloud.google.com/cloud-build/docs/cloud-builders">cloud builder image</a> and the steps. <a href="https://cloud.google.com/cloud-build/docs/build-config">Full documentation is here</a>. For my deployment, I’ve chosen to use the gcloud builder, because this is consistent with using the sdk command on my computer. So when I push to my master branch it will run <strong>gcloud app deploy</strong> automatically, which will install all of the npm dependencies too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/515ec802e0abf4fa7f783efbb1f0ac75/href">https://medium.com/media/515ec802e0abf4fa7f783efbb1f0ac75/href</a></iframe><p>3. <strong>package.json gcp-build step</strong></p><p>As I’m running a next.js application, I need to run next build for my application to work. You can add <a href="https://cloud.google.com/appengine/docs/standard/nodejs/running-custom-build-step">custom build steps</a> within package.json. Below shows the scripts that I have in my package.json with the gcp-build step</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/097b6716cef361b85c0b8683234edcce/href">https://medium.com/media/097b6716cef361b85c0b8683234edcce/href</a></iframe><p>Next we need to link to your repository. I had an existing repository already on Bitbucket, however you can choose to use a Google repository. While you’re logged into the Google Cloud Platform, make sure that you are on the correct project and in the left hand menu, scroll down until you see Source Repositories under the tools heading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*er3EgE89M0on9kCf7JOWlA.png" /></figure><p>You can then choose an empty repository or to link to an existing one from Bitbucket or Github. Once you’ve selected your project and linked to an existing repository or created a new one, you then need to setup a build trigger. You need to click on the settings for the repository which will take you to this page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GAAzWmjEgJHYzlJCcwrfzQ.png" /></figure><p>Click on the cloud build triggers link and click on create trigger. Choose the branch that you would like the build to trigger on and point the configuration file to the cloudbuild.yaml file created above and save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1ngLeuIN4VOzReQ-BdGFA.png" /></figure><p>OK so now we’re almost there. If you were to push to the master branch (or whichever branch you selected) then a build would run. However, this will fail at the moment because we need to <a href="https://console.developers.google.com/apis/api/appengine.googleapis.com/overview">enable the app engine API here</a>. Then you need to go to <a href="https://console.cloud.google.com/cloud-build">Cloud Builds</a> settings and enable App Engine Admin. Now it’s all ready! Go ahead and push/merge to your master branch.</p><p>You will be able to see all of the build logs within the <a href="https://console.cloud.google.com/cloud-build/">Cloud Builds page</a> and you can find your deployed app link on the <a href="https://console.cloud.google.com/appengine/services">App Engine Services page</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INrvuM6wNQnGDXM8CrczrA.png" /></figure><p>That’s it! definitely not as simple as Heroku but there are so many extra options available within Google App Engine that I’m still yet to explore.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bad2a17f2526" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/auto-deploy-node-app-to-google-app-engine-bad2a17f2526">Auto deploy a Node app to the Google App Engine</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why great developers suffer from imposter syndrome]]></title>
            <link>https://medium.com/charlottes-digital-web/why-great-developers-suffer-from-imposter-syndrome-d892c07b4c72?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d892c07b4c72</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[imposter-syndrome]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Wed, 09 Oct 2019 11:35:36 GMT</pubDate>
            <atom:updated>2019-10-09T11:35:36.714Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bougjsFO1pbOXheshHD4A.png" /><figcaption>Imposter syndrome written in a book. Image from <a href="https://www.pexels.com/">Pexels</a></figcaption></figure><p>I remember when I first heard the term imposter syndrome at a conference and it was a real revelation for me; in a room full of hundreds of talented lead developers, only a handful had never experienced this.</p><p>Imposter syndrome is essentially the feeling that you’re not good enough and you’ve got to where you have by accident. It sounds ridiculous when you say that; how could you have faked years of experience and delivering great projects? But it’s a very real feeling.</p><p>The thing I’ve learnt during my time in industry, is that imposter syndrome is usually the sign of a great developer. A developer can <strong>never</strong> know everything, technology is constantly changing, there are multiple correct ways to solve problems and we’re surrounded by people who know things that we don’t. A developer that thinks that they know everything isn’t usually someone that you want to work with.</p><p>Although imposter syndrome usually means a person is aware that they need to keep learning, it can also really hold people back. I’ve had friends who are amazing developers that I’ve really looked up to tell me that they fear interviews and that they don’t think they’re good enough for roles. It’s not simply a confidence thing either, as these are people who are really confident when they’re working on projects. <strong>It’s the awareness that people will know more than you on particular topics.</strong></p><p>So how can we overcome this feeling? I’m not sure we can ever overcome it completely, it’s the price we pay for being in an industry surrounded by really intelligent people and endless things to learn. One thing that’s really helped me over the years though is to embrace the knowledge of others, learn from them and you’ll find that they also learn from you. I remember years ago doing pair programming for the first time in a large company and I was terrified because I thought I’d look stupid in front of them. In the end we had great fun and we learnt from each other.</p><p><em>Tell your colleagues and friends that they are great, go to them for help when they know something you don’t and don’t be afraid of someone being better than you. A collaborative environment is far better than a competitive environment that just exacerbates imposter syndrome.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d892c07b4c72" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/why-great-developers-suffer-from-imposter-syndrome-d892c07b4c72">Why great developers suffer from imposter syndrome</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Netlify lambda functions to send emails in a GatsbyJS site]]></title>
            <link>https://medium.com/charlottes-digital-web/using-netlify-lambda-functions-to-send-emails-in-a-gatsbyjs-site-975a6c286ce6?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/975a6c286ce6</guid>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[netlify]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Tue, 08 Oct 2019 15:11:59 GMT</pubDate>
            <atom:updated>2019-10-08T15:13:52.051Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Netlify lambda functions to send emails from a GatsbyJS site</h3><p>I’ve recently created <a href="https://charlottesdigitalweb.com/">my website</a> using GatsbyJS and it’s brilliant. I come from a full stack background, with a lot of back-end experience in PHP so the <a href="https://jamstack.org/">JAM stack</a> is a different way of thinking for me. However, I’m all about embracing new technology!</p><p>My website is fairly simple and doesn’t really need a back-end so it seemed silly to use a CMS with a database; as a developer, I can easily add new information without the need for a fancy admin area. I do however have a contact form, so I needed to decide how I was going to send emails without a backend server.</p><p>Netlify does offer built in <a href="https://www.netlify.com/docs/form-handling/">form handling</a> but I was struggling to get this to work. It actually turns out that Gatsby wasn’t generating the static markup for this form so Netlify didn’t know about it (something to watch out for if your components are being hidden based on state). Also, I wanted the messages to go direct to my inbox, rather than checking on the Netlify site, so I decided lambda functions were the way to go.</p><p>Lambda functions basically allow you to create API endpoints without setting up a server. So I just needed to create an endpoint to send emails and call this endpoint when the form is submitted. I decided to use <a href="https://sendgrid.com/">Sendgrid</a> to send out my emails as I really like how you can keep track of activity and they have a really simple <a href="https://github.com/sendgrid/sendgrid-nodejs">node library</a>.</p><p><a href="https://www.gatsbyjs.org/blog/2018-12-17-turning-the-static-dynamic/">Setting up Netlify functions with Gatsby</a> is really simple and there is already an amazing post on this, so I won’t go into details. Once you’ve ran through the steps in that post, you then just store all of your functions as js files in your lambda directory. Each file must export a <strong>handler</strong> method with 3 parameters, event, context and callback.</p><ul><li><strong>event</strong> — is an object that contains details about the request, such as body and headers</li><li><strong>context</strong> — contains information about the context in which the function was called, e.g. identity user information</li><li><strong>callback</strong> — is a function that should be called to return either an error (as the first parameter) or a response object. (Although this actually isn’t needed for async calls)</li></ul><p>So, to create my lambda function was really simple. I first of all installed and saved the sendgrid dependency using npm and then created a new function called <strong>sendmail.js</strong> within the lambda folder. One of the reasons why you shouldn’t send things from the client side is because tokens can be stolen easily. Therefore, we need to store the sendgrid API token within Netlify. I also decided to store the email address to send the email message to here, so that it can be updated easily. To access environment variables, go to your Netlify site dashboard, click on settings and click on build &amp; deploy and then environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbQafWGoUgqvZYMpn0F-LA.png" /></figure><p>Ok, now we have the environment variables, let’s look at the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05ee49a63a8bfc46fbb21c3f60565041/href">https://medium.com/media/05ee49a63a8bfc46fbb21c3f60565041/href</a></iframe><p>For this function, you can see that we actually only use the event parameter and environment variables (from process.env). The form body is sent as JSON, so we simply parse this and get the values that we need from it. I decided to make it dynamic too and to send all of the fields within the body of my email, this means that if I decided to add another field to the form in future, the function won’t need updating.</p><p>The sendgrid documentation doesn’t mention error handling, however I didn’t want to just assume that the message had been sent. I’d rather tell a user that it failed so that I don’t miss out on an important message. I used async await and this caused me a bit of pain as I was getting errors such as UnhandledPromiseRejectionWarning: TypeError: Cannot read property &#39;statusCode&#39; of undefined when using the callback. It took a bit of hunting around to realise that <strong>if you are using an async function, you don’t use the callback, but simply return the response object!</strong></p><p>So now we have the function, how do we call it? First of all I created a state object to store all of my form fields. I’m using React hooks, so I’ve written mine this way, however if you are using React classes, simply add to your this.state object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/497bb80cd789b5ccf2ba011dcaf6c46d/href">https://medium.com/media/497bb80cd789b5ccf2ba011dcaf6c46d/href</a></iframe><p>I then attach a function onto the onChange event for each input element that will update this state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23da2a6f64ffd2c6a32bd0c7d9d42281/href">https://medium.com/media/23da2a6f64ffd2c6a32bd0c7d9d42281/href</a></iframe><p>Finally I created the submit handler below and attached it to onSubmit on my form element. This is just a skeleton, you can do whatever you need to do if the form sends or fails. On my site, I pop up a modal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08389e04b546b90e59e53ef3ce0776fb/href">https://medium.com/media/08389e04b546b90e59e53ef3ce0776fb/href</a></iframe><p>And that’s it! simple! Now this is very basic lambda function usage without authentication, etc. If you have functionality that requires authentication, I’d highly recommend <a href="https://www.gatsbyjs.org/blog/2018-12-17-turning-the-static-dynamic/">reading this post</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=975a6c286ce6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/using-netlify-lambda-functions-to-send-emails-in-a-gatsbyjs-site-975a6c286ce6">Using Netlify lambda functions to send emails in a GatsbyJS site</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redirecting anonymous users to the login form in Drupal 8]]></title>
            <link>https://medium.com/charlottes-digital-web/redirecting-anonymous-users-to-the-login-form-in-drupal-8-63da3c81a35d?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/63da3c81a35d</guid>
            <category><![CDATA[drupal-development]]></category>
            <category><![CDATA[drupal-8]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 20:36:29 GMT</pubDate>
            <atom:updated>2019-10-08T16:05:21.039Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes we need to make sure that anonymous users are redirected to the login page. In Drupal 7 we were able to use hook_init, this was called at the beginning of the page request. This has been removed in Drupal 8 due to events being introduced.</p><p>The event system is built on the Symfony event dispatcher and allows components to communicate with each other, whilst allowing them to remain modular. We can make use of the event dispatcher for many scenarios but in this example I will show you how to use it to redirect an anonymous user to the login page on any page load.</p><p>I’d recommend using <a href="https://drupalconsole.com/">Drupal Console</a> to generate the boilerplate eventdispatcher code. Simply create a module and then use the <strong><em>generate:event:subscriber</em></strong> command. When it asks if you want to load services from your container, enter yes and add the current_user service. This will create a class in your modules src &gt; EventSubscriber directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*XoSUBuyAfkuQfHal8GkqLg.png" /></figure><p>Below is the boilerplate code generated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2926965f2bc4990bc69c3083ab49bf91/href">https://medium.com/media/2926965f2bc4990bc69c3083ab49bf91/href</a></iframe><p>At the moment, this does not actually do anything. We will need to add an event subscriber, but what event do we need to subscribe to? Here are a list of available KernalEvents (taken from <a href="https://api.drupal.org/api/drupal/vendor!symfony!http-kernel!KernelEvents.php/class/KernelEvents/8.2.x">drupal.org 8,2,x API documentation</a>).</p><ul><li><strong><em>KernelEvents::CONTROLLER</em></strong> — The CONTROLLER event occurs once a controller was found for handling a request.</li><li><strong><em>KernelEvents::EXCEPTION</em></strong> — The EXCEPTION event occurs when an uncaught exception appears.</li><li><strong><em>KernelEvents::FINISH_REQUEST</em></strong> — The FINISH_REQUEST event occurs when a response was generated for a request.</li><li><strong><em>KernelEvents::REQUEST</em></strong> — The REQUEST event occurs at the very beginning of request dispatching.</li><li><strong><em>KernelEvents::RESPONSE</em></strong> — The RESPONSE event occurs once a response was created for replying to a request.</li><li><strong><em>KernelEvents::TERMINATE</em></strong> — The TERMINATE event occurs once a response was sent.</li><li><strong><em>KernelEvents::VIEW</em></strong> — The VIEW event occurs when the return value of a controller is not a Response instance.</li></ul><p>We need to check a user is anonymous and redirect them before page load if they are. So for this, we will be using the <strong><em>KernelEvents::REQUEST</em></strong> event.</p><p>The first step is to register this event subscriber in the getSubscribedEvents method</p><pre>static function getSubscribedEvents() {<br>  $events[KernelEvents::REQUEST][] = [&#39;onRequest&#39;, 30];<br>  return $events;<br>}</pre><p>The number 30 is the priority. This is set at 30 so that it runs before page caching (currently priority 27), otherwise it will cause issues and only work the first time it’s ran. <strong><em>onRequest</em></strong> is the name of the method that will be called on that event, the code for this is below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/287e6403776edd02b3fb9da366c9b298/href">https://medium.com/media/287e6403776edd02b3fb9da366c9b298/href</a></iframe><p>The method is pretty simple. It checks the current user, the current route name and redirects the user to the login page if they’re anonymous and not on any of the ignore routes. The ignore array is so that we don’t get an endless redirect loop when going to the login page and so that the user can still reset their password. Any routes that need to bypass this redirect can be added here.</p><p>Install the module, clear the cache and when you visit any page of your site as an anonymous user you will see that you’re redirected to the login page! This can easily be extended to redirect to certain pages for different scenarios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63da3c81a35d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/redirecting-anonymous-users-to-the-login-form-in-drupal-8-63da3c81a35d">Redirecting anonymous users to the login form in Drupal 8</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[In Drupal 7 we had view modes, where we could specify different views for an entity and show…]]></title>
            <link>https://medium.com/charlottes-digital-web/in-drupal-7-we-had-view-modes-where-we-could-specify-different-views-for-an-entity-and-show-8a5b4abb6c04?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a5b4abb6c04</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[drupal-8-development]]></category>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[drupal-8]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 20:28:19 GMT</pubDate>
            <atom:updated>2019-10-07T20:29:02.364Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Drupal 8 Entity Form Displays</h3><p><strong><em>In Drupal 7 we had view modes, where we could specify different views for an entity and show different fields within each view. Drupal 8 now extends this further and allows form display modes. These are incredibly useful, as they can be used to easily create multipart entity forms. For this example I’ll show you how you can split up a user registration form into multiple forms using the display modes.</em></strong></p><p>First of all, I’m going to add some custom fields to the user entity. You will need to login to the admin area, go to <strong><em>Configuration &gt; People &gt; Account Settings</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*NJnA5lLS8XpMYMLf6MSdqQ.png" /></figure><p>Next I am going to create two new form modes, one for the new registration form and one for the additional details form. Go to <strong><em>Structure &gt; Display Modes &gt; Form Modes</em></strong> and click on <strong><em>Add new form mode</em></strong>. Click on the User entity type and name your form mode. I am going to name mine ‘Simple Registration’ and ‘Additional Details’ and Drupal gives this these the machine names <strong><em>simple_registration</em></strong> and <strong><em>additional_details</em></strong>.</p><p>Now I’m going to go back to the <strong><em>Account settings</em></strong> configuration page and click on the <strong><em>Manage form display</em></strong> tab. At the bottom of the page, you’ll see a section called custom display settings. Click on the box to expand it and you will see the register display mode and the new ones just added, additional details and simple register. The register form mode is the default registration form mode, I am not editing this for this tutorial as this will also edit the admin add new user form, so it’s cleaner to add a whole new form and separate these. Select the new form modes and press save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*7lauEwdxSJyjsL4j0qsKzA.png" /></figure><p>Now at the top of the page, you will see the form modes appear as tabs. You can click on a form mode and specify which fields will appear for that mode. For the <strong><em>Simple Register</em></strong> form mode I will only show the username and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*IhRNKYEEJLrBXVv6DJlrew.png" /></figure><p>From the <strong><em>Additional Details</em></strong> form mode I will show the Picture, First Name and Last Name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*5ScjgSqBgg7ONauNbMQd3w.png" /></figure><p>Now that we have specified the form modes, we need to add in the forms. First of all we’ll need to create a new module. I use <a href="https://drupalconsole.com/">Drupal Console</a> to quickly create the boilerplate code for this. For the new registration form, I am going to extend the existing RegisterForm class. This already has all the checks built in for a new user and I am just going to change the save method to login the user and redirect to the second part of the form.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/108b1ae6511edcac1623e6a0d82157ff/href">https://medium.com/media/108b1ae6511edcac1623e6a0d82157ff/href</a></iframe><p>The final part of this form redirects to a route that we have not yet created. This will be the route name for the additional details form. To create this form, I will create a basic content entity form, extending the Drupal\Core\Entity\ContentEntityForm class. I am setting the field_first_name and field_last_name fields to required within the build method. This is because if you set a field to required within the entity field settings itself, it will mean that it will always be required on all form displays the field is included in. Adding it within this form class means they’ll only be required on this form.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f5f3d5a906bd27d2430afde7019d8cd/href">https://medium.com/media/8f5f3d5a906bd27d2430afde7019d8cd/href</a></iframe><p>The next step is to register these entity forms to the user entity. If creating forms for an entity that is within your module, you can add the forms to the entity class itself, within the annotations. Here is a section from the core User entity (core/modules/user/src/Entity/User.php).</p><pre>*     &quot;form&quot; = {<br>*       &quot;default&quot; = &quot;Drupal\user\ProfileForm&quot;,<br>*       &quot;cancel&quot; = &quot;Drupal\user\Form\UserCancelForm&quot;,<br>*       &quot;register&quot; = &quot;Drupal\user\RegisterForm&quot;<br>*     },</pre><p>As we are adding these forms to the core user entity, we will need to do this from within hook_entity_type_build. The name of the entity form should match the machine name for the form modes created earlier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d389dc2cb963053d193ca931e8a3d13f/href">https://medium.com/media/d389dc2cb963053d193ca931e8a3d13f/href</a></iframe><p>We now have form modes setup with their corresponding entity forms. The final step is to add in the routes so that we can get to the new registration forms. You will need to create a routing.yml file within your module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/695e24851d0485f6ebdf57864d4e16bf/href">https://medium.com/media/695e24851d0485f6ebdf57864d4e16bf/href</a></iframe><p>Now, when we enable the module we will be able to go to the new registration page (/register) and only the username and password fields show as defined in the form mode (the password will not appear if email verification is turned on).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*bHAmr3vad0LHU6537xjEvw.png" /></figure><p>When valid details are entered and the create new account button is clicked, it then logs the user in and redirects them to the additional details form. The fields from the additional_details form mode are shown on this form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*Q_iucDzrbrl6zvm4HjeAgg.png" /></figure><p>Now that the forms are in place, fields can be moved about within form modes and these changes will be reflected in the forms without the need to modify any code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a5b4abb6c04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/in-drupal-7-we-had-view-modes-where-we-could-specify-different-views-for-an-entity-and-show-8a5b4abb6c04">In Drupal 7 we had view modes, where we could specify different views for an entity and show…</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Formatting Date Time Entity Fields While Taking Daylight Saving Time (DST) Into Account In Drupal 8]]></title>
            <link>https://medium.com/charlottes-digital-web/formatting-date-time-entity-fields-while-taking-daylight-saving-time-dst-into-account-in-drupal-8-4ed600465aa7?source=rss-b4e1b5aac7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ed600465aa7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[drupal-8-development]]></category>
            <category><![CDATA[drupal-8]]></category>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Charlotte Bone]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 20:14:28 GMT</pubDate>
            <atom:updated>2019-10-07T20:14:28.434Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>When you create a date time field in Drupal 8, it stores the date in UTC format and takes into account daylight saving time (DST) too. This means that if you have a field that has a date that is after the switch to DST and the current date is before the switch, it will display the time an hour out if you haven’t formatted the date correctly.</em></strong></p><p>You might see a lot of examples out there that show you using the standard PHP date functions and pulling the raw value from the date field, however this does not work and will display the time an hour out even if you set the timezone. The best way, is to pull the DrupalDateTime object from the field. You can then get the timezone using drupal_get_user_timezone, set it on the field and then format the timezone and it will show the correct time.</p><p>The example below shows how you would do this for an entity field named field_start_date</p><pre>$date = $entity-&gt;field_start_date-&gt;date;<br>$timezone = timezone_open(drupal_get_user_timezone());<br>$date-&gt;setTimeZone($timezone);<br>$date-&gt;format(&quot;D d M Y H:i&quot;);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ed600465aa7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/charlottes-digital-web/formatting-date-time-entity-fields-while-taking-daylight-saving-time-dst-into-account-in-drupal-8-4ed600465aa7">Formatting Date Time Entity Fields While Taking Daylight Saving Time (DST) Into Account In Drupal 8</a> was originally published in <a href="https://medium.com/charlottes-digital-web">Charlotte’s Digital Web</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>