{"id":414,"date":"2013-11-09T22:28:20","date_gmt":"2013-11-10T05:28:20","guid":{"rendered":"http:\/\/www.keganv.com\/?p=414"},"modified":"2014-03-03T13:14:21","modified_gmt":"2014-03-03T20:14:21","slug":"change-user-disabled-exception-message-in-symfony-2","status":"publish","type":"post","link":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/","title":{"rendered":"Change User Disabled Exception Message In Symfony 2"},"content":{"rendered":"<p><a href=\"\/wp-content\/uploads\/translations-yml.png\"><img decoding=\"async\" src=\"https:\/\/www.keganv.com\/wp-content\/uploads\/translations-yml-610x270.png\" alt=\"Change User Disabled Exception Message In Symfony 2\"  class=\"aligncenter\" \/><\/a><\/p>\n<h3>The Problem<\/h3>\n<p>Symfony&#8217;s core message for when a user tries to log in, but is disabled is: &#8220;User account is disabled&#8221;. I guess that&#8217;s ok, but it&#8217;s really not very helpful to the user trying to log in. Initially, I set up an event listener in my bundle&#8217;s services.yml to a custom service that was intended to override the UserChecker.php core file (<code>Symfony\\Component\\Security\\Core\\User<\/code>). After this incorrect and unsuccessful attempt, I realized that I could just change the translations yaml file in my bundle. DUH!<br \/>\n<!--more--><\/p>\n<h3>The Solution<\/h3>\n<p>So here&#8217;s how you do it. If you don&#8217;t already have a translations folder set up in your bundle under the Resources directory, do so. In my case I am using the FOSUserBundle. So, I copied the FOSUserBundle.en.yml file to my directory (overriding the FOSUserBundle translations for English). Your structure should look like this: <code>Name\/MyBundle\/Resources\/translations\/FOSUserBundle.en.yml<\/code> In my case it has to be called &#8220;FOSUserBundle&#8221; so that the translation domain is correct. Below is the chunk of code I inserted into my yaml file.<\/p>\n<pre>\r\n# Security\r\n\"User account is disabled.\": Sorry, your account is pending review. An admin must enable and activate your account before you can log in.\r\n<\/pre>\n<p>The &#8220;# Security&#8221; is one of many comments used for separating the different categories of translations in the file. The &#8220;User account is disabled.&#8221; is the portion of text that I want to find, and the &#8220;Sorry, your account&#8230;&#8221; is the portion I want in return. For the project I am working on, an admin has to review and enable newly registered users before they can become active.<\/p>\n<p>Hopefully this post will come in handy for you and you don&#8217;t end up wasting a couple hours like I did trying to figure out how to do something that is actually stupid easy. Check out Symfony&#8217;s docs about <a href=\"http:\/\/symfony.com\/doc\/current\/book\/translation.html\" target=\"_blank\">translations<\/a> to learn more!<\/p>\n","protected":false},"excerpt":{"rendered":"The Problem Symfony&#8217;s core message for when a user tries to log in, but is disabled is: &#8220;User account is disabled&#8221;. I guess that&#8217;s ok, but it&#8217;s really not very helpful to the user trying to log in. Initially, I set up an event listener in my bundle&#8217;s services.yml to a custom service that was &#8230; <br\/> <a class=\"view-article btn btn-primary flip pull-left\" href=\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\"><span>View Article<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-414","post","type-post","status-publish","format-standard","hentry","category-coding-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Change User Disabled Exception Message In Symfony 2 | KeganV<\/title>\n<meta name=\"description\" content=\"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Change User Disabled Exception Message In Symfony 2 | KeganV\" \/>\n<meta property=\"og:description\" content=\"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\" \/>\n<meta property=\"og:site_name\" content=\"KeganV\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-10T05:28:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-03T20:14:21+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.keganv.com\/wp-content\/uploads\/translations-yml-610x270.png\" \/>\n<meta name=\"author\" content=\"Kegan V.\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kegan V.\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\"},\"author\":{\"name\":\"Kegan V.\",\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"headline\":\"Change User Disabled Exception Message In Symfony 2\",\"datePublished\":\"2013-11-10T05:28:20+00:00\",\"dateModified\":\"2014-03-03T20:14:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\"},\"wordCount\":288,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"articleSection\":[\"Coding &amp; Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\",\"url\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\",\"name\":\"Change User Disabled Exception Message In Symfony 2 | KeganV\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/#website\"},\"datePublished\":\"2013-11-10T05:28:20+00:00\",\"dateModified\":\"2014-03-03T20:14:21+00:00\",\"description\":\"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.keganv.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Change User Disabled Exception Message In Symfony 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.keganv.com\/#website\",\"url\":\"https:\/\/www.keganv.com\/\",\"name\":\"KeganV\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.keganv.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\",\"name\":\"Kegan V.\",\"logo\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.keganv.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Change User Disabled Exception Message In Symfony 2 | KeganV","description":"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/","og_locale":"en_US","og_type":"article","og_title":"Change User Disabled Exception Message In Symfony 2 | KeganV","og_description":"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.","og_url":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/","og_site_name":"KeganV","article_published_time":"2013-11-10T05:28:20+00:00","article_modified_time":"2014-03-03T20:14:21+00:00","og_image":[{"url":"http:\/\/www.keganv.com\/wp-content\/uploads\/translations-yml-610x270.png"}],"author":"Kegan V.","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kegan V.","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#article","isPartOf":{"@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/"},"author":{"name":"Kegan V.","@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"headline":"Change User Disabled Exception Message In Symfony 2","datePublished":"2013-11-10T05:28:20+00:00","dateModified":"2014-03-03T20:14:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/"},"wordCount":288,"commentCount":1,"publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"articleSection":["Coding &amp; Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/","url":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/","name":"Change User Disabled Exception Message In Symfony 2 | KeganV","isPartOf":{"@id":"https:\/\/www.keganv.com\/#website"},"datePublished":"2013-11-10T05:28:20+00:00","dateModified":"2014-03-03T20:14:21+00:00","description":"Learn how to easily change the disabled exception message in symfony for a user that has a disabled status using yaml.","breadcrumb":{"@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.keganv.com\/change-user-disabled-exception-message-in-symfony-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.keganv.com\/"},{"@type":"ListItem","position":2,"name":"Change User Disabled Exception Message In Symfony 2"}]},{"@type":"WebSite","@id":"https:\/\/www.keganv.com\/#website","url":"https:\/\/www.keganv.com\/","name":"KeganV","description":"","publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.keganv.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276","name":"Kegan V.","logo":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.keganv.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/414"}],"collection":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/comments?post=414"}],"version-history":[{"count":13,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":437,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/414\/revisions\/437"}],"wp:attachment":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}